AngularJs (1.X) 包括部分模板

标签 angularjs templates include partial

我的主布局文件中有这个

<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/

相关文章:

php - PHP包含文件中的 undefined variable 错误

angularjs - 你如何模拟 $http 给出 404?

javascript - 如何强制 Angular 使用 jqlite 或手动引用 jquery 对象

javascript - Angular $http.get 不传递参数

java - 自由标记 : read template from different path using class loader

c++ - Windows.h错误

php - 无法使用 AngularJS 和 PHP 发布

C# 如何在 get 属性中使用模板?

c++ - 基于 C++ 的变体国际象棋引擎设计问题

c++ - 在编译时将文件读入字符串