1

Defined a callback function definition in child

  private ModalNextAction: (callback?:(isUpdated: boolean) => void) => void;

its call back is defined as below. Parent returns if a modal can be opened or not

canOpenModalDialog() {
this.ModalNextAction = (canOpen) => {
  if (canOpen) {
    this.openDialog();
  } else {
  this.proceed();
  }
};
this.canOpen.emit();}

in ngOnInit subscribed as below in child

 this.sharedService.isUpdated.pipe(takeUntil(this.childDestroyed$)).subscribe(isUpdated=> {
  if(this.ModalNextAction) {
    this.ModalNextAction(() => isUpdated);
  }
})

Parent component will set

this.sharedService.isUpdated.next(true);

**IsUpdated** - flag is returned as true but when passed to **ModalNextAction** passed as a function as below. Why its passed as function?
ƒ () { return isUpdated; }
GANI
  • 2,013
  • 4
  • 35
  • 69

0 Answers0