我尝试使用Angular和Bluebird的承诺:
HTML:
<body ng-app="HelloApp">
<div ng-controller="HomeController">{{name}} {{also}}</div>
</body>
Run Code Online (Sandbox Code Playgroud)
JS:
// javascript
var app = angular.module('HelloApp', []);
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;
Run Code Online (Sandbox Code Playgroud)
[ 小提琴 ]
但是,不管我尝试了什么,它都会保持停留"$q promises"并且不会更新.除非我添加了一本$scope.$apply我宁愿避免使用的手册.
(我知道这是可能的,因为$ q会这样做)
我正在使用Bluebird 2.0,我在这里.