【发布时间】:2026-01-14 15:20:06
【问题描述】:
我正在使用ngInclude 指令来加载HTML 片段。现在我正在寻找传递动态 URL 的最佳方式。我知道我可以使用字符串连接创建 URL:
<ng-include src="'/foo/' + fooId + '/bar/' + barId + '/baz/' + bazId"></ng-include>
在我看来这有点丑。
ngHref 和 ngSrc 例如,接受包含 {{}} 标记的 URL。恕我直言,这种语法更简洁:
<img ng-src="/foo/{{fooId}}/bar/{{barId}}/baz/{{bazId}}"/>
<a ng-href="/foo/{{fooId}}/bar/{{barId}}/baz/{{bazId}}"/>
有没有更好的方法将动态 URL 传递给 ngInclude?p>
【问题讨论】:
标签: angularjs angularjs-directive angularjs-ng-include