How to Call REST API in AngularJs











<!DOCTYPE html>
<html>
<head>
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body>
<div ng-app="" ng-controller="iPController">
    <div id="ipInformation">
    IP - {{ipInfo.ip}}
    <br>
    About - {{ipInfo.about}}
    </div>
    <span>{{message}}</span>
</div>
<script>
    function iPController($scope,$http) {
        $http.get("http://jsonip.com")
                .success(function(response) {$scope.ipInfo = response;})
                .error(function(response) {
                    $scope.message="Error";
                });
    }
</script>
</body>
</html>

Test Code online - http://plnkr.co/edit/6amAYfVDkNQiDKk1jXkG?p=preview
Previous
Next Post »
Thanks for your comment