Search code examples
angularjsangularjs-routingangular-routing

Link executes twice - First time no variables initialized, second time intiliazed


UPDATE

It appears that the controller itself is only executed once, however, the following url is executed twice!

<a class="th" style="width: 64px;" href="#details/{{user.id}}">
    <img src="http://localhost:8080/project/show/{{user.id}}.png"/>
</a>

Apparantely, my end controller (Spring) first sees {{user.id}} as a parameter and then the actual value. Why is this executed twice???


Solution

  • Try to change in the link href to ng-href and in the img src to ng-src

    From the AngularJS documention about ngHref

    Using AngularJS markup like {{hash}} in an href attribute will make the link go to the wrong URL if the user clicks it before AngularJS has a chance to replace the {{hash}} markup with its value. Until AngularJS replaces the markup the link will be broken and will most likely return a 404 error. The ngHref directive solves this problem.

    and about ngSrc

    Using AngularJS markup like {{hash}} in a src attribute doesn't work right: The browser will fetch from the URL with the literal text {{hash}} until AngularJS replaces the expression inside {{hash}}. The ngSrc directive solves this problem.