Last active
August 29, 2015 13:26
-
-
Save orbitbot/827a22ac944308b5032b to your computer and use it in GitHub Desktop.
Extending angular $q promises example
This file contains hidden or 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
<!DOCTYPE html> | |
<html ng-app="extension-demo"> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script> | |
</head> | |
<body ng-controller="demoCtrl"> | |
<div> | |
{{ value }} | |
</div> | |
<div ng-show="done"> | |
Done! | |
</div> | |
<script type="text/javascript"> | |
angular.module('extension-demo', []) | |
.config(['$provide', function($provide) { | |
$provide.decorator('$q', function ($delegate) { | |
var defer = $delegate.defer; | |
$delegate.defer = function() { | |
var deferred = defer(); | |
deferred.promise.update = function(callback) { | |
return deferred.promise.then(null, null, callback); | |
}; | |
return deferred; | |
}; | |
return $delegate; | |
}); | |
}]) | |
.controller('demoCtrl', ['$scope', '$interval', function($scope, $interval) { | |
$interval(function(count) { | |
if (count === 10) | |
$scope.done = true; | |
}, 1000, 11) | |
.update(function(count) { | |
$scope.value = count; | |
}); | |
}]); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment