我正在尝试从一个页面重定向到另一个页面。每个页面都有自己的 Controller 。
我愿意
.controller('HomeCtrl', function ($scope, $location) {
$scope.settings = Helper.getLS('settings');
if (!$scope.settings) $location.path("/app/settings");
console.log('why am i seeing this?');
...
URL 正在更改,但问题是我仍然可以在控制台中看到日志,并且此页面中的其余功能仍在运行
我想停止执行并重定向并在新页面上运行另一个 Controller
有什么想法吗?
最佳答案
设置好路径后需要退出函数,以免后面的代码被执行。 $location.path()
不会停止代码和重定向。所以就这样做:-
if (!$scope.settings) {
return $location.path("/app/settings");
}
//Rest of the code
关于javascript - Angular 位置重定向仍然运行当前 Controller ,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25210559/