Created
September 8, 2016 11:26
-
-
Save Colorfulstan/5950c78b6daa2ac1e18b261f2ca6e7c9 to your computer and use it in GitHub Desktop.
Enable support for bluebird Promises in angular without needing $scope.$apply() http://www.unknownerror.org/opensource/petkaantonov/bluebird/q/stackoverflow/23984471/how-do-i-use-bluebird-with-angular http://jsfiddle.net/X4mAR/39/
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
function enablePromises(app) { | |
app.run(["$rootScope",function ($rootScope) { | |
Promise.setScheduler(function (cb) { | |
$rootScope.$evalAsync(cb); | |
}); | |
}]); | |
} | |
var app = angular.module('HelloApp', []); | |
enablePromises(app); | |
app.controller("HomeController", function ($scope) { | |
var p = Promise.delay(1000).then(function () { | |
$scope.name = "Bluebird!"; | |
console.log("Here!", $scope.name); | |
}).then(function () { | |
$scope.also = "Promises"; | |
}); | |
$scope.name = "$q"; | |
$scope.also = "promises"; | |
}); | |
window.app = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment