我的主布局文件中有这个
<body>
<header id="header" ng-controller="HeaderController"></header>
<div class="container" ng-view></div>
我的目录结构中有一个 header.html 部分模板。
如何将此模板包含在我的应用中?我以为 Angular 在处理 Controller 后会自动包含模板,但它不起作用。
header 节点应替换为该文件的内容。
最佳答案
包含外部文件中的模板/html 片段的一种方法是使用 ng-include
指令 ( doc )。
<ng-include src="'/path/to/the/header.html'"></ng-include>
或
<div ng-include src="'/path/to/the/header.html'"></div>
关于AngularJs (1.X) 包括部分模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22329769/