我发现自己一次又一次地重复相同的代码片段,是有可能做这样的事情在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 –