包括一个外部的.html角模板 [英] Including angular templates on one external .html
问题描述
在棱角分明,您可以创建在页面的模板本身,如:
In angular, you can create a template in the page itself like:
<script type="text/ng-template" id="something.htm">
<div>This is a template.</div>
</script>
我想知道如果你可以采取一帮这些,并把它们一起在外部网页,如templates.htm,然后引用整个页面,从根本上说:看在templates.htm模板的东西热媒。
I'm wondering if you can take a bunch of these and put them together in an external page, like "templates.htm", and then reference the entire page, essentially saying "look in templates.htm for the template something.htm."
推荐答案
如果你不介意的性能略有下降,这里是我在评论说工作的例子。
If you don't mind a little decrease in performance, here is a working example for what I have said in the comment.
示例: http://plnkr.co/编辑/ EcEySnmmm3hsLimDHfYr?p = preVIEW
关键概念是删除 NP-应用
和引导应用程序后手动 templates.html
是加载。
The key concept is to remove the np-app
and bootstrap the app manually after the templates.html
is loaded.
$.get('templates.html').done(function (rawHtml) {
angular.module('app').run(function ($compile) {
$compile(rawHtml)({});
});
angular.element(document).ready(function () {
angular.bootstrap(document, ['app']);
});
});
这篇关于包括一个外部的.html角模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!