【问题标题】:How can i access to my elements which are content projected?我如何访问内容投影的元素?
【发布时间】:2021-07-23 23:03:55
【问题描述】:

我有芯片列表组件。在其中,我投射了一个输入和一个其他组件。但我想访问输入。

 <app-chip-list>
     <input #input [id]="autoCompleteSearchInput" type="text" autoComplete="off"
        class='input-underline search-bar idented-text' [placeholder]="placeholder" 
     [formControl]="search" />
     
     <app-chips [chips]="chips" class="chips" (removeChip)="removeChip($event)"></app-chips>

 </app-chip-list>

现在在我的芯片列表组件中,我需要访问这些投影元素。

例如对整个app-chips 组件和我的输入。

如何访问它们?

【问题讨论】:

    标签: angular


    【解决方案1】:

    使用@ContentChild:

    @ContentChild('input') theInput: ElementRef;
    @ContentChild(ChipsComponent) theChipsComponent: ChipsComponent;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      • 2020-05-12
      • 1970-01-01
      相关资源
      最近更新 更多