In depth
Single merge Model and Template into View
Nesting DOM elements in directives template.
Property require in directive
var promise = $http.get("/api/my/name");
promise.success(function(name) {
console.log("Your name is: " + name);
});
promise.error(function(response, status) {
console.log("The request failed with response " + response + " and status code " + status);
});
////////////////////////////////////////////////////////////////////////////////////////////////
// Same thing, diffrent way //
////////////////////////////////////////////////////////////////////////////////////////////////
$http.get("/api/my/name").then(
/* success */
function(response) {
console.log("Your name is: " + response.data);
},
/* failure */
function(error) {
console.log("The request failed: " + error);
});
////////////////// $http ////////////////////////
var users; // A place to store our data
// Setup the request.
var myHttpPromise = $http.get('users');
// Call the request.
myHttpPromise.then(function(response) {
// Handle the response.
users = response.data;
});
////////////////// $resource //////////////////
var MyResource = $resource('/users/:userId', { userId:'@userId' });
var getUser = function (userId) {
return MyResource.get({ userId: userId }).$promise;
}