[英]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.