angular - angular8 es5子调用父方法调用this.method未定义
问题描述
export class SonComponent extends ParentComponent {
public say() {
console.info('hello!my parent is ' + super.getName());
}
}
export class ParentComponent {
public getName() {
return this.getFirstName() + this.getLastName(); // <--- exception, core.js:4002 ERROR TypeError: this.getFirstName is not a function
}
public getFirstName() {
return 'wu';
}
public getLastName() {
return 'victor';
}
异常,core.js:4002 错误类型错误:this.getFirstName 不是函数
为什么?
解决方案
你的组件中的构造函数在哪里......???当你扩展 ParentComponent
childs 的构造函数应该调用 ParentComponent,找到 ref 的代码
export class SonComponent extends ParentComponent {
constructor(){
super();
}
public say() {
console.info('hello!my parent is ' + super.getName());
}
}
希望这可以解决您的问题...并且在 ts/js 天气中,您是否提到返回类型并不重要,除非您严格期望特定类型的响应
推荐阅读
- java - 使用 JPA Hibernate 的多个多对多
- javascript - 无法访问 datamuse api 上的 JSON 数据
- python - Exporting image intensities from multiple files in multiple folders to excel in Python
- chromium - Chromium in headless mode is not getting media stream from webcam
- flutter - Flutter 是否也在 iOS 上使用 Skia 进行渲染?
- c - 对带有#define 的预处理器指令的好奇心
- node.js - Firebase 函数无法部署:SyntaxError: Unexpected token function
- python - how to remove part of url using python
- android - React Native - 具有 2 列的 FlatList 未按预期运行
- java - Threads in swing freezing - java