【发布时间】:2014-09-16 17:13:56
【问题描述】:
我从一个演示 Ionic 应用程序开始 (ionic start myApp sidemenu)、and added a resolve to one of the views:
resolve: {
issue: function($q, $timeout) {
var defer = $q.defer();
//defer.reject(); // Doesn't work browser or device
$timeout(defer.reject); // Works in browser, but not device
return defer.promise;
}
}
我在这里监控拒绝resolves:
.run(function($ionicPlatform, $rootScope, $ionicLoading) {
$ionicPlatform.ready(function() {
// regular stuff here
$rootScope.$on('$stateChangeError', function() {
$ionicLoading.show({
template: 'All good!'
});
});
});
});
由于某种原因,如果resolve 立即拒绝(参见上面的defer.reject()),则不会运行$stateChangeError 的回调。如果我在 Ionic 之外做同样的事情,it works!
此外,尝试通过执行 $timeout(defer.reject); 来延迟 resolve 拒绝会导致不同的行为。现在它可以按预期在浏览器中运行,但仍然无法在设备上运行。尝试延迟更多,结果在设备上成功:
$timeout(function() {
defer.reject();
}, 250); // Doesn't work for me with 200 or less
有人能解释一下吗?
【问题讨论】:
-
嗨,米莎。我刚刚克隆了你的 Github repo 并运行了命令: ionic run --device android 离子加载模式正确出现。您是在 android 或 ios 设备上尝试这个吗?是否有您正在使用的特定设备?如果你使用模拟器会出现这种情况吗?
-
发现了一个错误github.com/driftyco/ionic/issues/1751 相应地更新了我的答案
-
@bhantol 谢谢,这对我有帮助!
标签: angularjs ionic-framework angular-ui-router