Home > Software design >  How to get output eventemitter boolean value in parent ts file?
How to get output eventemitter boolean value in parent ts file?

Time:07-25

I have below code in my child component

@Component({
    selector: 'app-child'
})
export class ChildComponent {

    @Output()
    dataDeleted: EventEmitter<boolean>;

    constructor() {
        this.dataDeleted = new EventEmitter<boolean>();
    }

    delete() {
        this.dataDeleted.emit(true);
    }
}

I tried using @Input() dataDeleted: boolean; in parent ts file. but it's not working.

CodePudding user response:

In Parent component:

  1. Add event listener to the child selector. The $event is an angular specific variable which is a generic name for what ever you emitted from the child component, in your case it holds the boolean value.

HTML:

<app-child (dataDeleted)="onDataDeleted($event)"></app-child>
  1. Add a method to call when event is emitted.

TS:

onDataDeleted(val:boolean)
{
 
}

You can read this guide

  • Related