我發現自己一次又一次地重複相同的代碼片段,是有可能做這樣的事情在AngularJS:是否可以在AngularJS模板中創建可重用的片段?
<div ng-snippet="mySnippet">
This is a snippet
</div>
<div ng-snippet="anotherSnippet">
Yet another snippet!!
</div>
<ng:include src="anotherSnippet">
<ng:include src="anotherSnippet">
<ng:include src="mySnippet">
和上面會輸出:
Yet another snippet!!
Yet another snippet!!
This is a snippet
我不一定在尋找這個確切的「ng:include」解決方案或模式,但會減少我的模板中的重複。
完美,謝謝! – DaveJ
太棒了。你希望輸入鏈接到不同對象的表單以及輸入的不同名稱的情況如何? https://plnkr.co/edit/iCOIq88e7gSSYaE92b0t?p=preview –