【发布时间】:2015-07-27 13:51:59
【问题描述】:
根据服务中的逻辑,我会路由到不同的视图。为了方便服务注入,我使用加载控制器来确定下一步要去哪里。
这很好用,只是我不能通过加载控制器“返回”。如何检测后退按钮,或修复我的加载模型使其更友好?
.when('/loading', {
templateUrl: '/app/views/mystuff/loading.html',
controller: 'LoadingController'
})
angular.module('app').controller('LoadingController', ['$location', 'WhereService',
function ($location, WhereService) {
if (!WhereService.doneWithA()) {
$location.path('/a');
}
else if (!WhereService.doneWithB()) {
$location.path('/b');
}
else {
location.href = "/myapp/somewhereelseentirely"//this is fine
}
}]);
angular.module('app').controller('ALoadingController', ['$location', 'AService',
function ($location, AService) {
if (!AService.isDone()) {
$location.path(AService.currentPath());
}
else {
$location.path('/');//triggers loading controller above
}
}]);
【问题讨论】:
-
如果我理解正确,您无法返回,因为按下返回按钮会将您导航到
/loading路线,LoadingController接管并导航您返回到目前看来?如果是这种情况,在LoadingController中执行$location.replace()在每个之前$location.path('...')可能会有所帮助。
标签: javascript angularjs browser-history ngroute