0

I have two components: AppComp and SimulationComp

AppComp contains one function :

generateEmptyPromise() {
   return Promise.resolved('')
}

and has the following html :

<simulation-comp (simu)='generateEmptyPromise()'></simulation-comp>

Simulation comp handles the (simu) like this :

@Output() simu = new EventEmitter()
private eventHandled: boolean = false

// Triggered when a button of the component is pressed
whenClicked() {
  this.simu.subscribe(() => {
     this.eventHandled= true
  })
  this.simu.emit()
}

What I would like is eventHandled to become true based on the promise given by generateEmptyPromise (so after that the emit has been handled). However, it's not working atm, how could I adapt my code to have this behavior ? Maybe it is not supposed to work like this, and I am getting it completly wrong here.

Scipion
  • 11,449
  • 19
  • 74
  • 139
  • Possible duplicate of [Can I emmit the event from parent to child in angular2](http://stackoverflow.com/questions/39738974/can-i-emmit-the-event-from-parent-to-child-in-angular2) – ranakrunal9 Sep 28 '16 at 12:03

1 Answers1

0

@Output is for sending values 'outside' of the component back to the parent. Child -> Parent.

For Parent -> Child Communication where the parent template consist of the child it wants to communicate with you need @Input so the child knows the parent will send those values at some point in time.

So for starting you might want appCmp

<simulation-comp [myinput]='generateEmptyPromise()'></simulation-comp>

Inside

SimulationCmp.ts

@Input myinput : any //Whatever value type you expect it to be

Nico
  • 1,961
  • 17
  • 20