有没有办法将指令附加到 Angular2 中的组件?
Is there any way to attach a directive to a component in Angular2?
我有一个简单的面板组件:
<app-box></app-box>
它有一个模板:
<div class="box">
<div class="box-header">
<h3>Box Header</h3>
<small>Subtitle of this box</small>
</div>
</div>
我是否可以使用附加到它的指令,以便我可以像这样操作 DOM:
<app-box subtitle="false"></app-box>
当 subtitle
是 false
我想删除 small
元素。
此外,这是一种错误的技术吗?
使用输入:
@Input() subtitle: boolean;
在你的 html:
<small *ngIf="subtitle">...</small>
我有一个简单的面板组件:
<app-box></app-box>
它有一个模板:
<div class="box">
<div class="box-header">
<h3>Box Header</h3>
<small>Subtitle of this box</small>
</div>
</div>
我是否可以使用附加到它的指令,以便我可以像这样操作 DOM:
<app-box subtitle="false"></app-box>
当 subtitle
是 false
我想删除 small
元素。
此外,这是一种错误的技术吗?
使用输入:
@Input() subtitle: boolean;
在你的 html:
<small *ngIf="subtitle">...</small>