I will suggest not trying to invoke the parent method in the child. Consider using an event emitter to communicate to the parent from the child https://angular.io/guide/component-interaction#parent-listens-for-child-event.
Parent Component:
export class ParentComponent implements OnInit {
.....
onSayHello() {
// Execute some code
}
}
Parent Component Template:
<p>parent</p>
<children (sayHello)="onSayHello()"></children>
Child Component
@Component({
selector: 'child-component',
templateUrl: './child-component.component.html',
styleUrls: ['./child-component.component.scss']
})
export class ChildComponent implements OnInit {
@Output() sayHello = new EventEmitter();
.....
sayHello() {
this.sayHello.emit(); // you can send any variable to parent
}
}
When this.sayHello.emit();
is fired, your handler in your parent element (`onSayHello) will be called.
Here is a stackblitz demo