angularjs - refresh when clicked on link with actual url

后端 未结 10 1292
深忆病人
深忆病人 2020-12-02 10:13

I use routeProvider to define controlers and templates for my urls.

When I click on the link, which has the same url as is the actual location, nothing happens. I w

10条回答
  •  佛祖请我去吃肉
    2020-12-02 10:35

    Add a / (slash) to the defined url in the route configuration

    I met a similar problem today, I have a link in my web page and when I click it, I want the ng-view reload each time, so that I can refresh data from server. But if the url location doesn't change, angular doesn't reload the ng-view.

    Finally, i found a solution to this problem. In my web page, I set the link href to:

    But in the route config, I set:

    • $routeProvider.when('/test/', { controller: MyController, templateUrl:'/static/test.html' });

    The different is the last slash in url. When I click href="#/test" for the first time, angular redirect the url to #/test/, and load ng-view. when i click it second time, because the current url is #/test/, it's not equal to the url in the link (href="#/test") I clicked, so Angular triggers the location change method and reloads the ng-view, in addition Angular redirects the url to #/test/ again. next time i click the url, angular does the same thing again. Which is exactly what I wanted.

    Hope this was useful for you.

提交回复
热议问题