0
votes

I'm using a RAD software that generates Angular code.

It always generates 2 components, a "generated" one, and a empty one where you can put some custom functions.

I want to call from the empty one, let's call it the child component, a function that is present in the "parent" component.

To explain it better, here follows the declaration of the 2 components (they are in the same folder):

Parent component:

export class MainViewGenerated implements AfterViewInit, OnInit, OnDestroy {

  constructor(private injector: Injector) {}

 myFunc() {
      console.log("hello World")
  }

Child component:

export class MainViewComponent extends MainViewGenerated {

  constructor(injector: Injector) {
    super(injector);
  }

so what is the correct syntax to call, from the Child component, the function "myFunc()" declared in the Parent component?

1

1 Answers

2
votes

You can call the method of your parent component using the super keyword:

export class MainViewComponent extends MainViewGenerated {
  constructor(injector: Injector) {
    super(injector);
    super.myFunc();
  }
}