English 中文(简体)
正在等待的安吉斯事件
原标题:await Angular s EventEmitter
问题回答

您可使用firstValueFrom

兑现承诺,将可观测的承诺归于兑现,并兑现承诺,一旦从可观测到的数值中得出第一价值,这一承诺将尽快解决。 然后将停止订阅。

It turns everithing that is subscriptable in a promise. Will be something like this:

import { firstValueFrom } from  rxjs ;
@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 firstValueFrom(this.childComponentRef.instance.dataChanged).then(() => {
      alert( emited! );
    })

  }
}

http://www.learnrxjs.io/learn-rxjs/operators/filtering/first"rel=“nofollow noreferer”>first(),以等待活动者的第一价值:

      openChild() {
        ...
        await this.childComponentRef.instance.dataChanged.pipe(first()).toPromise()
        alert( emited! )
      }

you can emit whenever you want from child component like

this.dataChanged.emit(yourData);

and in your parent component you can try catch that event using

this.childComponentRef.instance.dataChanged.then((res) => {
   console.log(res);
});




相关问题
Angular matSort not working on Date column by desc

Trying to sort the material table with date column , date format is MM/DD/YYYY ,h:mm A , order of date is not by latest date and time. Anything which i missed from the below stackblitz code. https:/...