Angular 1 and Angular 2 Integration

How to call Restful APIs/Services in AngularJs?

In the AngularJs, we can use following methods to achieve this.
1.      $http Service
2.      $resource Service
3.      Rest Angular

The example as,

<!DOCTYPE html>
<html>

<head>
  <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
  <script src="https://code.angularjs.org/1.5.8/angular.js"></script>
  <script>
    var appController = function($scope, $http) {
      $http.get("http://jsonip.com")
        .success(function(response) {
          $scope.Info = response;
        })
        .error(function(response) {
          $scope.message = "Error!!";
        });
    }
  </script>
</head>

<body>
  <div ng-app ng-controller="appController">
    <h3>How to call Restful APIs/Services in AngularJs?

</h3>
    <div>
      IP - {{Info.ip}}
      <br/> About - {{Info.about}}
    </div>
    <span>{{message}}</span>
  </div>
  <br/>
  <div>
    <a href='http://www.code-sample.com/2014/09/angularjs-documentation.html' target='_blank'>For more..</a>
  </div>
</body>

</html>

The output as,



ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.