【问题标题】:Call method from parent class after call method from child class从子类调用方法后从父类调用方法
【发布时间】:2018-07-09 13:22:40
【问题描述】:

我有父类扩展的父类和子类。 父类是应用程序每个页面上显示的菜单 - 因此它被应用程序中的所有子类扩展。

我尝试这样做: 1.从返回子类的父类调用方法 2.对子类(SearchPage)做一些动作 3. 使用父类导航到其他页面(子)

在第 3 步我得到错误。我认为这与循环依赖有关,但我找不到任何解决方法。我找不到解决办法。

 E/launcher - Error: TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/home/kamil/Projects/automatedmt/tmp/LearnerApp/pages/SearchPage.js:19:36)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/kamil/Projects/automatedmt/tmp/LearnerApp/LEPPage.js:3:22)
at Module._compile (module.js:652:30)

[14:52:27] E/launcher - 进程退出,错误代码为 100

【问题讨论】:

  • 你是从子类中调用“super()”来调用父类中的构造函数吗?
  • 查看您所描述问题的一些代码将是????
  • @nowy 请看我之前的问题stackoverflow.com/questions/51206739/…
  • 我知道你为什么会收到这个错误,明天会回答。你应该用几句话来做组合而不是继承。
  • @Oleksii 我在等你的回答 :)

标签: javascript angular typescript protractor automated-tests


【解决方案1】:

根据您提供的内容很难判断错误。

我假设这是由于您在子构造函数中缺少super()super()用于调用父类中的构造函数,将相关的服务、参数等传递给父类。

parent.component.ts

export class ParentComponent {

  constructor(public http: HttpClient) { }

}

child.component.ts

export class ChildComponent extends ParentComponent {

  constructor(public http: HttpClient) { 
    super(http)
  }   
}

【讨论】:

猜你喜欢
  • 2017-11-09
  • 2012-02-22
  • 2014-06-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多