我需要拦截 ng-view 的变化并加载“loading div”覆盖层,直到加载所有新图像。
我正在尝试暂停 HttpInterceptor 中的 Promise 回调,但无法再次解析我的 Promise。
这里是一个例子:
return function (promise) {
globalForTest = $q.defer();
return promise.then(function (response) {
console.log('first', response);
return globalForTest.promise;
}).then(function (response) {
console.log('second', response);
return response;
});
当我尝试调用 globalForTest.resolve(value) 时,没有任何反应,也没有错误。
最佳答案
它有效,但由于您在 Angular 生命周期之外调用resolve
,因此您需要 explicitly call $scope.$apply
使事物运转起来。否则不会调用回调。
关于javascript - AngularJS 中的 deferred.resolve(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17426413/