Skip to content

Instantly share code, notes, and snippets.

View gsans's full-sized avatar
🚁
Hawaii is Awesome

Gerard Sans gsans

🚁
Hawaii is Awesome
View GitHub Profile
var deferred = $q.defer();
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
deferred.resolve(resultObj); //triggers fnSuccess
deferred.reject(reasonObj); //triggers fnFailure
deferred.notify(progressObj); //triggers fnNotification
.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();
})
$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.
});
angular.module(“myapp”, [‘ngMockE2E’])
<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”});
<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”});
<profile data=”user”></profile>
scope : { local_data: “=data” } //using alias
scope : { data: “=” } //abbreviation when using identical names
//Usage:
// local_data = 1;
// data = 1;
<profile id=”1"></profile>
scope : { local_id: “@id” } //using alias
scope : { id: “@” } //abbreviation when using identical names
//Usage:
// var profile_id = local_id;
// var profile_id = id;