This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var deferred = $q.defer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var promise = deferred.promise; | |
//basic version | |
promise.then(fnSuccess) | |
.catch(fnFailure) //optional | |
.finally(fnAlways) //optional | |
//advanced version | |
promise.then(fnSuccess, fnFailure, fnNotification) | |
.catch(fnFailure) //optional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deferred.resolve(resultObj); //triggers fnSuccess | |
deferred.reject(reasonObj); //triggers fnFailure | |
deferred.notify(progressObj); //triggers fnNotification |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$http.get('movies.json') | |
.then(function(response){ | |
$scope.movies= response.data; | |
}) | |
.catch(function(error){ | |
console.log(error); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory("Movies", function($http, $q) { | |
return { | |
get: function() { | |
var deferred = $q.defer(); | |
$http.get('movies.json') | |
.then(function(response){ | |
deferred.resolve(response.data); | |
}) | |
.catch(function(error){ | |
deferred.reject(error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.run(function($httpBackend, Users) { | |
//mock users api | |
$httpBackend.whenGET('/api/users') | |
.respond( Users.get() ); | |
//you can mock GET, POST, HEAD, PUT, DELETE, PATCH, JSONP. See $httpBackend help. | |
// allow other requests to use $http. Eg: templates | |
$httpBackend.whenGET(/.tpl.html$/).passThrough(); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$http({method: 'GET', url: '/api/Users'}). | |
success(function(data, status, headers, config) { | |
// this callback will be called asynchronously | |
// when the response is available | |
$scope.users = data; | |
}). | |
error(function(data, status, headers, config) { | |
// called asynchronously if an error occurs | |
// or server returns response with an error status. | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module(“myapp”, [‘ngMockE2E’]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<profile onAlert=”alert(message)”></profile> | |
scope : { local_onAlert: “&onAlert” } //using alias | |
scope : { onAlert: “&” } //abbreviation when using identical names | |
//Usage: | |
// local_onAlert({message:”hey”}); | |
// onAlert({message:”hey”}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<profile onAlert=”alert(message)”></profile> | |
scope : { local_onAlert: “&onAlert” } //using alias | |
scope : { onAlert: “&” } //abbreviation when using identical names | |
//Usage: | |
// local_onAlert({message:”hey”}); | |
// onAlert({message:”hey”}); |
OlderNewer