gpt4 book ai didi

javascript - 通过加载 Controller 保持后退按钮的 Angular ?

转载 作者:行者123 更新时间:2023-12-02 15:54:38 25 4
gpt4 key购买 nike

根据服务中的逻辑,我会路由到不同的 View 。为了促进服务注入(inject),我使用加载 Controller 来确定下一步要去哪里。

这非常有效,只是我无法通过加载 Controller “返回”。如何检测后退按钮,或修复我的加载模型以使其更友好?

    .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
}
}]);

最佳答案

听起来你需要$location.replace():

If called, all changes to $location during current $digest will be replacing current history record, instead of adding new one.

https://docs.angularjs.org/api/ng/service/ $地点

关于javascript - 通过加载 Controller 保持后退按钮的 Angular ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31654997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com