当我尝试从基于https://github.com/jhades/angular2-library-example
的库中的类扩展时ie - lib中的类:
export class Stuff {
foo: string = "BAR";
}
我的应用中的课程
export class SomeClass extends Stuff {
}
我总是收到以下错误:
EXCEPTION: Uncaught (in promise): Error: Error in :0:0 caused by: Class constructor Stuff cannot be invoked without 'new'
TypeError: Class constructor Stuff cannot be invoked without 'new'
at new HomeComponent (http://localhost:3000/main.bundle.js:46859:16)
at new Wrapper_HomeComponent (/AppModule/HomeComponent/wrapper.ngfactory.js:7:18)
at CompiledTemplate.proxyViewClass.View_HomeComponent_Host0.createInternal (/AppModule/HomeComponent/host.ngfactory.js:15:29)
at CompiledTemplate.proxyViewClass.AppView.createHostView (http://localhost:3000/main.bundle.js:58198:21)
at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (http://localhost:3000/main.bundle.js:58458:52)
at ComponentFactory.create (http://localhost:3000/main.bundle.js:28964:25)
at ViewContainerRef_.createComponent (http://localhost:3000/main.bundle.js:42370:45)
at RouterOutlet.activate (http://localhost:3000/main.bundle.js:46144:40)
at ActivateRoutes.placeComponentIntoOutlet (http://localhost:3000/main.bundle.js:15248:16)
at ActivateRoutes.activateRoutes (http://localhost:3000/main.bundle.js:15222:22)
at http://localhost:3000/main.bundle.js:15177:58
at Array.forEach (native)
答案 0 :(得分:0)
由于您不会继承父组件类的元数据,因此无法扩展组件。
本文可以帮助您了解问题所在:
https://medium.com/@ttemplier/angular2-decorators-and-class-inheritance-905921dbd1b7