gpt4 book ai didi

javascript - 如何在特定的 $location.url() 上运行函数?

转载 作者:行者123 更新时间:2023-11-30 17:37:49 25 4
gpt4 key购买 nike

我想在用户点击新 View 和位置/view 时更改页面的一些 内容。我说 some 是因为如果我要更改 all 内容,我会知道使用 routeProvider 并加载新模板。

那么,当 $location.url() 更改为 'dash/new' 时,我怎样才能让下面的函数起作用?

$scope.currentRoute = $location.url();

if currentRoute == 'dash/my' {
console.log('go!')
}

在 Angular JS 中基于 $location.url() 改变东西不好吗? The documentation说是“观察和观察”,但如果您不能根据它采取行动,那么还有什么选择?

最佳答案

查看$route documentation .它具有您可以使用的 $routeChangeStart$routeChangeSuccess 等事件。在您的 Controller 中订阅这些事件并执行必要的逻辑。

关于javascript - 如何在特定的 $location.url() 上运行函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21692294/

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