在游戏中!框架,我可以执行以下操作来 DRY 我的布局代码:
在 main.html 中:
<h1>This is main</h1>
#{doLayout /}
<div id="footer">Footer content</div>
在 home.html 中:
#{extends 'main.html' /}
<p>This is the home page content</p>
我想在 AngularJS 中做同样的事情,即我想创建一个 HTML 文件并让它从另一个文件继承。我看到有 ngInclude 指令,但使用它会在我当前的应用程序中导致大量布局代码重复。如果 AngularJS 本身不支持它,是否有任何其他 HTML 模板解决方案支持?
谢谢。
最佳答案
ng-view
指令使用来自路由器的新数据/模板更新当前元素,因此您可以制作通用布局并使用 ng-view
,并且如果您仍然有重复代码;使用 ng-include
。
关于javascript - 扩展 AngularJS 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12135606/