Colorfulstan
9/8/2016 - 11:26 AM

Enable support for bluebird Promises in angular without needing $scope.$apply() http://www.unknownerror.org/opensource/petkaantonov/bluebir

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;