【发布时间】:2016-06-11 03:07:31
【问题描述】:
版本:“angular2”:“2.0.0-beta.6”
我们假设我们有两个@Directive
HighLightDirectiveUnderlineDirective
如何创建实现这两个@Directive 的@Component?
@Component({
selector: 'test',
template: '{{text}}',
//Looking from something like that..
//using: [HighLightDirective, UnderlineDirective]
})
export class TestComponent {
public text:string;
//maybe? constructor(hightlight,underline)
}
PS:我知道我可以通过更改组件模板来做到这一点,如下所示。是否存在更优雅的东西?
'<div highlight underline>{{text}}</div>'
【问题讨论】:
-
这正是指令的用途,以及你应该如何使用它们(:你给
{{ text }}的例子有点微不足道,因为其他所有属性指令都是很好的解决方案。你有更具体的东西吗?想好了吗? -
@Sasxa 我对在我制作的每个组件上添加一个 div 容器感到很困惑。当
<test>my_text</test>看起来更容易时,它会创建<test><div>my_text</div></test>:] -
在父模板中使用
<test highlight underline></test>。 -
事实上我不想允许没有这两个指令的 TestComponent 实例,这就是为什么这个解决方案也不能工作。
-
我不清楚这个问题要求什么。作曲的效果应该是什么?
标签: angular