2016-03-28 2 views
0

は、私はクラスの代わりに提供のためのトークンとして文字列を使用しようとしている:角2は()にES5の文字列を指定しますか?

app.RandomComponent = ng.core 
    .Component({ 
     selector: "randomComponent", 
     template: "Component!", 
     providers: [ 
      ng.core.provide("Stuff", {useValue: "Hello"}) 
     ] 
    }) 
    .Class({ 
     constructor: ["Stuff", function(stuff) { 

     }] 
    }); 

しかし、それはエラーがスローされます:EXCEPTION: Cannot resolve all parameters for 'class5'(Stuff). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'class5' is decorated with Injectable.

それは、少なくともTSで動作するはずhttps://angular.io/docs/ts/latest/api/core/Provider-class.htmlによると:/

答えて

1

Inject documentationによると、あなたのケースでは

When @Inject() is not present, Injector will use the type annotation of the parameter.

あなたは、単純な文字列を注入しているが、あなたのスタッフのための型として文字列をangular2使用することはできません。したがって、これらのケースでは、あなたは

.Class({ 

    // Note the ng.core.Inject 
    constructor: [ng.core.Inject("Stuff"), function(stuff) { 
     console.log(stuff); 
    }] 
}); 

がここにあなたのコードの作業とplnkrだ次のようにng.core.Injectを使用する必要があります。

関連する問題