2017-02-22 37 views
0

延长类当我尝试从一个类,它是在一个库基础上扩展https://github.com/jhades/angular2-library-example从angularjs 2库

即 - 类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

是的,我包括它 –

回答

0

由于您不会继承父组件类的元数据,因此无法扩展组件。

这篇文章可以帮助您了解是什么问题:

https://medium.com/@ttemplier/angular2-decorators-and-class-inheritance-905921dbd1b7

+0

哦,这很奇怪,它在应用程序的一部分,而不是一个库的时候工作。所以这个问题只发生在组件上,只有当扩展类如果在一个依赖库中呢? –

+0

是的...希望你通过链接 –

+0

我已经做了,但它没有说明为什么它只影响图书馆的类。此外,我刚刚测试从普通类继承(而不是组件),而且这也不起作用 –