使用angular将常用模板加载到html页面中
loading common templates into an html page with angular
我有一个页面,其中包含在我的应用程序的多个页面中常见的详细信息部分。我正在努力减少代码冗余,并创建这些将与页面一起加载的迷你视图。
在主要的详细信息页面中,我有一个部分,我正试图使用ng-include 加载
<div ng-show="checkProducts()">
<hr style="margin-bottom:5px!important"/>
<p><strong><em>Products</em></strong></p>
<div class="bs-associationPanel">
<ng-include src="commontemplates/productView/shoes"></ng-include>
</div>
</div>
我不能在这里使用路由,因为这就像主详细信息页面中的部分视图,该页面已经在使用路由加载它并将它绑定到控制器。
src
值是APP中一个名为productView.html 的html页面的路径
我把它包装在一个带有id 的脚本ng-template
标签中
<script type="text/ng-template" id="shoes">
<table class="table table-condensed table-responsive">
<thead>
<tr>
<th>brand</th>
<th>color</th>
<th>size</th>
</tr>
</thead>
<tbody ng-repeat="s in detail.shoes">
<tr>
<td>{{s.brand}}</td>
<td>{{s.color}}</td>
<td>{{s.size}}</td>
</tr>
</tbody>
</table>
</script>
我希望这会起作用,但当我渲染页面时,我没有寺庙,看着元素浏览器,我看到了以下
<!-- ngInclude: undefined -->
我想我已经很接近了,只是不知道我错过了什么。关于如何实现或能否实现这一点,有什么建议吗?
基本上,类型为text/ng-template
的脚本由angular&angular将其视为模板,然后将这些模板放入$templateCache
服务中,以实现更快的检索。
src
属性的模板名称应该用'
单引号括起来,这样它就可以通过$templateCache
查找模板。
<ng-include src="'commontemplates/productView/shoes'"></ng-include>
相关文章:
- Webpack:如何将原始HTML加载为React JSX
- 画布 HTML 加载时间
- 使用 Ajax 在 html 加载后调用 jquery 插件
- 用javascript(不带外部文件)将html加载到另一个html中
- 错误 404 时,通过 jQuery 将 HTML 加载到 DIV 中
- 如何在将 html 加载到对话框中后更改标签的文本
- 如何将数据从服务器呈现的 html 加载到模型中
- jQuery 从外部 html 加载内容
- Ajax 将 html 加载到页面上并使用页面 js 不起作用
- 如何在没有安全警告的情况下将一个 html 加载到另一个 html 中
- 安卓:根据上一次活动列表中的选择,修改本地静态html加载的JS
- 在AppStore发布时,iOS应用程序上的index.html加载路径不正确
- 使jquery.load在HTML加载之前发生
- 使用jqueryload方法将ajax响应数据作为内部html加载到页面元素中
- HTML加载用户单击按钮时输入的输入字段数
- jQuery Mobile从新html加载第二个页面
- 使用ajax将html加载到Datatable子行中
- 使用JavaScript将HTML加载到DIV
- 使用JS和JQuery替换AJAX中的字符串或html加载
- js函数加载的页面无法使用js函数js-html加载另一个页面