Skip to content

Instantly share code, notes, and snippets.

@dankahle
Last active August 29, 2015 14:05
Show Gist options
  • Save dankahle/712f6a4fe234d96bb0c4 to your computer and use it in GitHub Desktop.
Save dankahle/712f6a4fe234d96bb0c4 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html ng-app="app">
<head>
<title>index.html</title>
<style>
</style>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.17/angular.min.js"></script>
</head>
<body ng-controller="ctrl">
<script>
var app = angular.module('app', []);
app.controller('ctrl', function ($scope, $interval) {
$scope.$watch(function () {
console.log('watch'); // for watching the digest loop
})
var p = $interval(function (val) {
console.log('interval fcn', val);
}, 100, 3, false);
p.then(function (val) {
console.log('success', val);
$scope.$digest();
}, function (val) {
console.log('error', val);
$scope.$digest();
}, function (val) {
console.log('notify', val)
})
});
</script>
</body>
</html>
@dankahle
Copy link
Author

output >>>>>
(2) watch // 2 digests before the loop
interval fcn 0
notify 0
interval fcn 1
notify 1
interval fcn 2
notify 2
success 3
watch // the $scope.$digest call from success fcn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment