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

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.