0
votes

Why is my EventEmitter not working?

Calling the function sendInstruction() the EventEmitter doesn't work, but testing in ngOnInit the event reaches on parent component, what is happening?

child component.ts

@Output() updateInstruction = new EventEmitter<boolean>();

sendInstruction() {
    this.objDetails = this.titleDetails.DetalhesTitulo
    const send: SendInstruction = {
      ...
    }
    this.service.sendInstruction(send, this.objDetails.NN_ABC).subscribe({
      next: () => {
        this.emitInstruction(true)
      },
      error: () => 
        ...,
    });
  }

  emitInstruction(emit){
    this.updateInstruction.emit(emit)
  }

child component.html

<button class="abc-button select medium col-top" mat-raised-button color="primary" [disabled]="!hasInstruction || formInstructions.invalid"
        (click)="sendInstruction()">    
            Send Instruction
</button> 

parent component.ts

getDetailsUpdate(update) {
    console.log(update);
}

parent component.html

<abc-instruction-billet (updateInstruction)="getDetailsUpdate($event)"></abc-instruction-billet>
1
How to import your "EventEmitter", it should be import from @angular/core.Raheem Mohamed
When you call this.service.sendInstruction is your observable emitting any value? What does it return?Tombery
@RaheemMohamed yeah i'm already importing from @angular/core.Pedro Melo
@Tombery The response is just a 200, calling emitInstruction() inside or outside service happens the same thing, nothing.Pedro Melo

1 Answers

0
votes

You need to subscribe to your observable like this.

this.service.sendInstruction(send, this.objDetails.NN_ABC).subscribe(()=> {
    this.emitInstruction(true)
},error => {
    ....,
});