更新时间:2023-12-05 19:56:16
在每个子组件中,添加输出:
In each of your child components, add an output:
@Output
initialized = new EventEmitter<boolean>();
并在您确定组件已初始化(或如您的问题所述已加载)时发出一个事件,因此可以显示下一个事件:
and emit an event when you decide that the component is initialized (or loaded, as your question says), and that the next one can thus be displayed:
ngOnInit() {
...
this.initialized.emit(true);
}
在父组件中,有一个计数器:
In the parent component, have a counter:
counter = 0;
每次初始化组件时都增加计数器,直到计数器允许显示组件时才显示组件:
Increment the counter every time a component is initialized, and don't display a component until the counter is allowing it to be displayed:
<child1-component (initialized)="counter++"></child1-component>
<child2-component (initialized)="counter++" *ngIf="counter > 0"></child2-component>
<child3-component (initialized)="counter++" *ngIf="counter > 1"></child3-component>
<child4-component (initialized)="counter++" *ngIf="counter > 2"></child4-component>