Tell me how to do requests for an API from an anguly? get post put delete? googled but apparently there for old versions of the article
- oneWhat does it mean for older versions? As far as I can imagine, there were no fundamental changes in this part. Or does the question say about Angualar 2? In this case, it must be explicitly specified. - Qwertiy ♦
|
1 answer
API requests are normal requests. There are two ways to do this in Angular.
$ http - a service allowing to do ajax requests. Has methods such as get , post , etc.
Example:// Simple GET request example: $http({ method: 'GET', url: '/someUrl' }).then(function successCallback(response) { // this callback will be called asynchronously // when the response is available }, function errorCallback(response) { // called asynchronously if an error occurs // or server returns response with an error status. });
$ resource - service, add-on service $ http, simplifies working with the RESTful API
Example:var User = $resource('/user/:userId', {userId:'@id'}); User.get({userId:123}, function(user) { user.abc = true; user.$save(); });
- oneAnd the code can or will be too much? - Nick Volynkin ♦
- @NickVolynkin, are the trivial examples from the help copy? - Grundy
- @NickVolynkin, added - Grundy
- oneThank you) Any code for someone is trivial. - Nick Volynkin ♦
|