2017-02-22 12 views
0

からクラスを拡張 - libにクラス:はangularjs 2ライブラリ

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

私はそうしましたが、なぜそれがライブラリのクラスだけに影響するのかは何も言いません。また、私はちょうど通常のクラス(コンポーネントではない)から継承してテストしたが、どちらも動作しません –