Link 执行两次 - 第一次没有初始化变量,第二次初始化
Link executes twice - First time no variables initialized, second time intiliazed
更新
看起来controller本身只执行了一次,然而下面url执行了两次!
<a class="th" style="width: 64px;" href="#details/{{user.id}}">
<img src="http://localhost:8080/project/show/{{user.id}}.png"/>
</a>
显然,我的终端控制器 (Spring) 首先将 {{user.id}} 视为参数,然后才是实际值。为什么要执行两次???
首先,我建议您使用 ui-router
,它比标准 ng-router
.
更强大
然后 link 使用 href
的 ng-href
脚背。
确保 href
link 仅在 model
正确绑定时才加载,否则您可能会得到 link,例如:href="#details/"
甚至最差 href="#details/undefined"
尝试将 link href
更改为 ng-href
并将 img src
更改为 ng-src
来自 AngularJS 关于 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.
大约 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.
更新
看起来controller本身只执行了一次,然而下面url执行了两次!
<a class="th" style="width: 64px;" href="#details/{{user.id}}">
<img src="http://localhost:8080/project/show/{{user.id}}.png"/>
</a>
显然,我的终端控制器 (Spring) 首先将 {{user.id}} 视为参数,然后才是实际值。为什么要执行两次???
首先,我建议您使用 ui-router
,它比标准 ng-router
.
然后 link 使用 href
的 ng-href
脚背。
确保 href
link 仅在 model
正确绑定时才加载,否则您可能会得到 link,例如:href="#details/"
甚至最差 href="#details/undefined"
尝试将 link href
更改为 ng-href
并将 img src
更改为 ng-src
来自 AngularJS 关于 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.
大约 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.