gpt4 book ai didi

javascript - 使 AngularJS Controller 中的 $location 无效

转载 作者:行者123 更新时间:2023-11-28 06:14:00 25 4
gpt4 key购买 nike

我正在编写一个 Angular 单页面应用程序,其中通过公共(public) View 和公共(public) Controller (使用 ui-router)呈现许多“页面”。要使用的数据存储在服务中的分层对象中,并使用 URL 组件检索它。也就是说,如果我有 URL #/getstarted/get ,则会从 myService.getContents().getstarted.get 读取内容。

这工作得很好,但有一个异常(exception):当我想导航到其中另一个页面时,没有任何反应。为了到达另一个页面,我必须访问由另一个 Controller 控制的页面。

显然,当我单击具有相同 Controller 的状态的链接时,该 Controller 不会再次解析(这可以从“console.log调试”中看到),因此从中检索数据的参数不会刷新。

有没有办法(在回调中、在 module.config 中或在 ui-sref 的某些咒语中)使 Controller 数据无效?

最佳答案

如果你有一个 plunkr,会更容易测试,但尝试以下变体:

$stateProvider.state('somewhere', {
url:'/somewhere',
cache:false,
templateUrl:function(params) {
return 'some/calculated/path/view.html'
},
controllerProvider:[function() {
return 'HomeController';
}]
});
每次都应调用

templateUrlcontrollerProvider...

关于javascript - 使 AngularJS Controller 中的 $location 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36134279/

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