JSFiddle - React, Tailwind, and code Playground
by Pablo Leone
HTML
<div ng-app>
<div ng-controller="ctrl">{{greeting}}</div>
</div>
JavaScript
function ctrl($scope, $q, $timeout) {
$scope.getValue = function (name) {
var deferred = $q.defer();
// this emulate an async call to the api/uri
$timeout(function () {
deferred.notify('About to greet ' + name + '.');
deferred.notify('Another about to greet ' + name + '.');
if (name === 'hola') {
deferred.resolve('Hello, ' + name + '!');
} else {
deferred.reject('Greeting ' + name + ' is not allowed.');
}
}, 1000);
return deferred.promise;
};
$scope.getValue('hola').then(function (greeting) {
alert('Success: ' + greeting);
}, function (reason) {
alert('Failed: ' + reason);
}, function (update) {
alert('Got notification: ' + update);
});
}