Issue
my base class
:
import { Component, VERSION } from '@angular/core';
import { Feature } from './super.component';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent extends Feature {
name = 'Angular ' + VERSION.major;
constructor() {
super();
}
superToCall(value) {
console.log('value', value);
}
}
super class
:
export class Feature {
childCalled(value) {
console.log('child called', value);
}
}
how to pass the param to superToCall
from childCalled
method?
Solution
Make your parent class (Feature
) abstract and add an abstract function superToCall
(which the children must implement):
export abstract class Feature {
childCalled(value) {
console.log('child called', value);
this.superToCall(value);
}
abstract superToCall(value);
}
All children (which extend Feature
) must now implement the abstract method superToCall
:
export class AppComponent extends Feature {
constructor() {
super();
}
override superToCall(value) {
console.log('value', value);
}
}
Answered By - TmTron
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.