简体   繁体   English

如果不使用路线,则检测角度的位置变化

[英]detecting location change in angular if route do not used

I have a simple menu on the page, who looks like this 我在页面上有一个简单的菜单,看起来像这样

<ul>
<li><a href="#/home">home</a></li>
<li><a href="#/work">work</a></li>
</ul>

So when I pressing to the link my path change and I want to bind some data retrieval logic for that moment. 因此,当我按链接时,我的路径改变了,我想在那一刻绑定一些数据检索逻辑。

So my question is how I could track that location was changed??? 所以我的问题是如何跟踪该位置已更改???

I'm not sure if $routeChangeStart event will fire in this case, but you can watch $location path for changes 我不确定在这种情况下是否会触发$routeChangeStart事件,但是您可以观察$location路径中的更改

$scope.$watch(function() {
    return $location.path();
}, function() {
    //callback
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM