angularjs – refresh when clicked on link with actual url

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:

  • <a href="#/test">test</a>

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)