2017-12-09 1 views
3

角度4つの支持体には、クラスは、誰もが現在 私はその提案を避けてくださいES6を切り替えることはできないのですES5構文で角度5を提供することができますがありません。 ES6に切り替えると、あなたはあなたのコンポーネント クラス 機能の静的プロパティannotationsparametersを使用する必要が今アンギュラ5

答えて

4

ののように私は4の角に、このような何か固執する唯一の方法である場合:

function Service() {} 

function AppComponent(service) { 
    console.log(service); 
} 

AppComponent.prototype.ngOnInit = function() { 
    console.log('test ngOnInit'); 
}; 

AppComponent.annotations = [ 
    new Component({ 
    selector: 'my-app', 
    template: '<h1>Example of Angular 5.0.5 in ES5</h1>', 
    viewProviders: [Service] 
    }) 
]; 

AppComponent.parameters = [ Service ]; 

Plunker Example

+0

回答を更新しました – yurzui