Is it possible to await till Angular EventEmitter emits, like it's possible to await ajax call (Angular 5 synchronous HTTP call)?
What I want to do is:
Having a Child component
@Component({
template: '<button (click)="emit1()">emit</button>'
})
export class ChildComponent {
@Output() dataChanged: EventEmitter<number> = new EventEmitter<number>(true); // synchronous
emit1(){
this.dataChanged.emit(1)
}
}
And a Parent component that dynamically creates a Child component
@Component()
export class ParentComponent {
childComponentRef: ComponentRef<ChildComponent>
constructor(private resolver: ComponentFactoryResolver, private vcRef: ViewContainerRef) {}
openChild() {
const factory = this.resolver.resolveComponentFactory(ChildComponent);
this.childComponentRef = this.vcRef.createComponent(factory);
await this.childComponentRef.instance.dataChanged.toPromise()
alert('emited!')
}
}
I want to (a)wait until the value is emitted from a Child component.