angular dom 属性内的花括号

angular curly braces inside dom attribute

我正在尝试将 html 导入 angular 到 link 到动态页面。

//SampleController
$scope.id = 1;
//sample.html
<p>{{id}}</p> <!-- 1 -->
<link rel="import" href="/samples/{{id}}">

<p> 标签显示了 id 但是 href 属性给出了错误...

cannot GET /samples/%7B%7Bid%7D%7D 404

花括号似乎没有在 href 属性内部展开。我可以做这样的事情吗?

使用ng-href

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

<link rel="import" ng-href="/samples/{{id}}">