(与我在Programmers.SE上的另一个问题高度相关:https://softwareengineering.stackexchange.com/questions/280249/whether-to-abstract-small-repeating-code-segments-in-html-templates)
当我想重用几行HTML时,我不得不在另一个文件中编写一些JavaScript模板来创建一个指令,这真的很烦人。我真的想在同一个HTML文件中创建一个标记指令。
然后我想到了一个想法:我可以创建一个特殊的指令(下面的custom-tag)来声明一个来自HTML的指令。
例如:
<custom-tag name="icon" params="{which: '@which'}">
<span class="glyphicon glyphicon-{{which}}" />
</custom-tag>它将转换为一些JavaScript,如:
module.direcrtive('icon', {
restrict: 'E',
scope = {which: '@which'},
template = '<span class="glyphicon glyphicon-{{which}}" />',
});我可以称之为
<icon which="asterisk" />我的问题是,这样的东西是否已经存在于角度上了?
(我知道这只是重新发明了其他一些模板框架,但我需要使用this。)
发布于 2015-04-29 10:30:26
有三种方法(afaik)在角度上引用模板:
template属性中。templateId引用。<script type="text/ng-template" id="template_id.html"> .... </script>中的同一页中定义。并通过templateId: "template_id.html"引用。关于此的更多详细信息:Using Inline Templates in Angularhttps://stackoverflow.com/questions/29940063
复制相似问题