答案 0 :(得分:0)
我认为ngComponentOutlet正是您所寻找的: https://angular.io/api/common/NgComponentOutlet
然后你可以这样做:
<a (click)="doSwitch()">Switch</a>
<ng-container *ngComponentOutlet="component1"></ng-container>
<ng-container *ngComponentOutlet="component2"></ng-container>
打字稿中的:
Input()
component1: Type<any>;
Input()
component2: Type<any>;
...
使用组件时:
<switch-component [component1]="comp1" [component2]="comp2"></switch-component>
comp1: Type = ParentComponent1;
comp2: Type = ParentComponent2;