Note that there are some explanatory texts on larger screens.

plurals
  1. POangularjs - refresh when clicked on link with actual url
    primarykey
    data
    text
    <p>I use routeProvider to define controlers and templates for my urls. </p> <p>When I click on the link, which has the same url as is the actual location, nothing happens. I would like the <code>reload()</code> method to be called if a user clicks on such a link even if the location hasn't changed. In other words, if I set the location to the same value, I would like it to behave the same as if I would set it to different value.</p> <p>Is there a way to configure routeProvider or locationProvider to do it automatically? Or what is the right approach to do this? This is stadard behaviour in round trip applications, but how to do it in angularjs?</p> <p>I've asked it on <a href="https://groups.google.com/forum/#!topic/angular/VcaYuIuGhCM" rel="noreferrer">google groups</a> as well.</p> <p>UPDATE:</p> <p>This question is getting lots of views, so I will try to explain how I solved my problem. </p> <p>I created a custom directive for linking in my app as Renan Tomal Fernandes suggested in comments. </p> <pre><code>angular.module('core.directives').directive('diHref', ['$location', '$route', function($location, $route) { return function(scope, element, attrs) { scope.$watch('diHref', function() { if(attrs.diHref) { element.attr('href', attrs.diHref); element.bind('click', function(event) { scope.$apply(function(){ if($location.path() == attrs.diHref) $route.reload(); }); }); } }); } }]); </code></pre> <p>The directive is then used for all links in my app I want to have this functionality.</p> <pre><code>&lt;a di-href="/home/"&gt;Home&lt;/a&gt; </code></pre> <p>What this directive does is that it sets the <code>href</code> attribute for you based on <code>di-href</code> attribute so angular can handle it like always and you can see the url when you hover over the link. Furthermore when user clicks on it and the link's path is the same as the current path it reloads the route.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload