【发布时间】:2021-09-14 18:43:56
【问题描述】:
我只想在子组件完成 http 调用后才在父组件中呈现子组件,但这对我不起作用,子组件不显示...
child selector in parent component
<app-child-component *ngIf="alert" (alert)="propagar($evento)"></app-child-component >
export class ParentComponent implements OnInit {
alert = false;
propagar(evento: boolean) {
this.alert = evento;
}
export class ChildComponent implements OnInit {
@Output alert = new EventEmitter<boolean>();
ngOnInit() {
this.childComponentService.getSomething().subscribe(response => {
if(this.response.code === 200)
this.alerta.emit(true);//here I just want the child component to be displayed
})
}
}
但它不起作用,即使服务正确响应,子组件也永远不会显示
【问题讨论】:
标签: angular typescript rxjs