[英]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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.