-1

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.

Mike
  • 13
  • 9
  • Please let us know what you haven't found in this page before posting: https://angular.io/guide/component-interaction#parent-listens-for-child-event – Vega Jul 25 '22 at 07:12

1 Answers1

0

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

ayala
  • 331
  • 1
  • 9