簡體   English   中英

有什么方法可以將指令附加到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>

subtitlefalse我要刪除small元素。

另外,這是錯誤的技術嗎?

使用輸入:

@Input() subtitle: boolean;

並在您的html中:

<small *ngIf="subtitle">...</small>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM