April 2015
Intermediate to advanced
278 pages
5h 38m
English
If we are developing a component for AngularJS, then we should use all the benefits and advantages that this framework provides, such as Promises, caching, mocking, and so on. For XHR, AngularJS provides an easy-to-use function that implements Promises. Let's take a look at an example:
var url = "files/access.log";
$http.get(url)
.then(function(response){
console.log(response.data);
});Looks pretty neat, doesn't it? This is exactly why we want to use an abstraction provided by AngularJS. Now, we can make an HTTP request with all the advantages from the AngularJS world. For completeness, let's also look at the POST request:
var url = "files/access.log"; var data = {'test': 'my-data'}; $http.post(url, data) .then(function(response){ ...Read now
Unlock full access