根據某些條件,我有可以包含10個不同子組件中的1個的組件。<div *ngIf="type === 1"> <component_1></component_1></div><div *ngIf="type === 2"> <component_2></component_2></div><div *ngIf="type === 3"> <component_3></component_3></div>...在該組件中,我需要一個可以隨時返回正確的子組件引用的方法(例如,單擊按鈕時)。getComponentRef() { switch (this.type) { case 1: { // return component_1 ref; break; } case 2: { // return component_2 ref; break; } case 3: { // return component_3 ref; break; } ... }}任何想法 ?
Angular,在單擊按鈕時動態獲取組件引用
幕布斯6054654
2021-04-24 14:15:58