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:
- 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>
- Add a method to call when event is emitted.
TS:
onDataDeleted(val:boolean)
{
}
You can read this guide