javascript - My AngularJS client isn't consuming my RESTful call -
i trying feet wet on angularjs consumes restful service, however, running issue.
i have rest call, http://localhost:8080/application/webapi/myapp/, returns following json:
{ "content": "hello world", "id": 1 }
also, have following angularjs controller:
var myapp = angular.module("mymodule", []) .controller("hello", function($scope, $http) { $http.get('http://localhost:8080/application/webapi/myapp/'). success(function(data) { $scope.greeting = data; }); });
and index.html has following,
<div ng-controller="hello"> <p>the id {{greeting.id}}</p> <p>the content {{greeting.content}}</p> </div>
where ng-app defined in body tag.
but when run index.html, on tomcat server, doesn't consume rest call. instead, produces blanks binding expressions are.
my index.html looks this:
my first application! id content
i not sure why doesn't consume rest call?
my index.html should say,
my first application! id 1 content "hello world"
but doesn't :(.
from angular doc
the $http legacy promise methods success , error have been deprecated. use standard method instead. if $httpprovider.uselegacypromiseextensions set false these methods throw $http/legacy error.
try this
$http.get('http://localhost:8080/application/webapi/myapp/'). then(function(result) { $scope.greeting = result.data[0]; });
Comments
Post a Comment