3
我见过一堆与此非常相似的问题,但我是Angular的新手,所以他们不是,相当有意义。这里是我的sitaution:基于属性的指令中的动态模板?
我定义的指令:
robus.directive("titlebar", function() {
return {
restrict: "E",
scope: { title: '@title' },
template: "<header class='bar-title'><h1 class='title'>{{title}}</h1></header>",
replace: true
}
});
我使用这个指令是这样的:
<titlebar title="{{workout.name}}"></titlebar>
理想情况下,我想可选属性添加到这一点,像:
<titlebar title="{{workout.name}}" editButton="true" closeButton="true"></titlebar>
如何在template
定义中处理这些问题?我一直在阅读关于我需要重写的一个$compile()
函数,但尚未明确如何这样做。模板只是简单的字符串,所以我觉得我可以将它们内联,而将它们作为单独的文件引用。
谢谢!
啊,那太好了。有意义的是,你可以在模板中使用'ng-show' - 甚至没有想到要使用它们! – dmackerman