i new angularjs. searching accessing services restful api, didn't idea. how can that?
option 1: $http service
angularjs provides $http
service want: sending ajax requests web services , receiving data them, using json (which talking rest services).
to give example (taken angularjs documentation , adapted):
$http({ method: 'get', url: '/foo' }). success(function (data, status, headers, config) { // ... }). error(function (data, status, headers, config) { // ... });
option 2: $resource service
please note there service in angularjs, $resource
service provides access rest services in more high-level fashion (example again taken angularjs documentation):
var users = $resource('/user/:userid', { userid: '@id' }); var user = users.get({ userid: 123 }, function () { user.abc = true; user.$save(); });
option 3: restangular
moreover, there third-party solutions, such restangular. see documentation on how use it. basically, it's way more declarative , abstracts more of details away you.
Comments
Post a Comment