2017-04-05 4 views
0

角2のアプリケーションで、「エラー:./SampleComponentクラスのSampleComponent - インラインテンプレートによるエラー:厳密なモードで変数が定義されていません」というエラーが発生しました。 しかし、このエラーはIE 10でのみ発生します。角2のインラインテンプレート:厳密なモードで変数が定義されていません

<input type="text" class="form-control" name="name" formControlName="name" placeholder="Name" [nameFormatter]="selected"> 

ここ属性ディレクティブnameFormatterに渡された「selected」値がcomponent.Ifで初期化されている変数である私は、これはとそれをfine.Assigning動作しているようですいくつかの静的な値を持つselected変数を削除してみてくださいselected変数によりこの問題が発生します。

export class NameComponent implements OnInit { 
    public selected : string; 

    someFunction(){ 
     this.selected="some value" //The value changes depending on some conditions 
    } 
} 

polyfillsとは何か関係ありますか。以下のpolyfillをindex.htmlに追加してみました。

<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script> 
    <script src="https://npmcdn.com/angular2/es6/dev/src/testing/shims_for_IE.js"></script> 
    <script src="https://unpkg.com/core-js/client/shim.min.js"></script> 

誰かが私にこのことを教えてください。

+0

をそして、あなただけの変数を初期化してみてくださいましたか? 'public selected:string =" "; – Arg0n

+0

tanx @ Arg0n.私はそれらを追加しようとしました。しかし、効果は同じようです。 – Outlooker

+0

あなたはより多くのコードを投稿する必要があります。このコンポーネントのhtmlを見ることはできますか?一般に、 'strictモードでは変数が定義されていません 'というエラーは、var宣言を使用しないために' strict mode'(TSがデフォルトで使用する)で起こるので、 'somevar = 5'エラーが発生します。' var somevar = 5' –

答えて

0

this内側somefunctionNameComponentを参照していないため、別の閉鎖です。

あなたの目標は、ビュー(html)から関数を呼び出すことである場合、この操作を行います。

export class NameComponent implements OnInit { 
    public selected : string; 

    someFunction(){ 
    this.selected="some value" //The value changes depending on some conditions 
    } 
} 
+0

Typo.my bad.edited the question.The関数は 'NameComponent'を使っています。 – Outlooker

関連する問題