2016-01-08 9 views
7

私が作成したControlGrouptheFormAngular2:エラー - FormBuilder</strong><strong>を使用してプロパティ 'updateValue' タイプに存在しません 'AbstractControl'

は、私はそれがうまく働いた。この

this.theForm.find('MainImageId').updateValue(id, true, true);

のようなコントロールの値を更新しようとしたときが、WebStormは私が間違っているのは何

Error:(148, 24) TS2339: Property 'updateValue' does not exist on type 'AbstractControl'.

というエラーが表示さ?それはなぜ機能するのですか?

+0

実行時にWebStormに実行時情報がありません。 'theForm.find()'のソースコードの戻り値の型を確認してください –

+0

Gotcha。 AbstractControlです。角度のgitHub [here](https://github.com/angular/angular/blob/2.0.0-β0/modules/angular2/src/common/forms/model.ts#L305-L411)を参照してください。 。 しかし、どうすればいいですか? –

答えて

9

Typescript casting object's propertyによると、私はこれはそれ

findは今getで修正する必要がありますね(> = RC.5)

(<Control> this.theForm.find('MainImageId')) .updateValue(id, {onlySelf:true, emitEvent:true}); 

    // (<Control> this.theForm.find('MainImageId')) .updateValue(id, {onlySelf:true, emitEvent:true}); 

編集:オプションのパラメータは、第二引数のObjectとして供給されています。

+0

素敵に完了! 1つ以上のパラメータを受け入れることが期待される一方で、[ここ](https://github.com/angular/angular/blob/2.0.0-beta.0/modules/angular2/src /common/forms/model.ts#L239-L305)。エラー:(146,5)エラー:(146,5)TS2346:指定されたパラメータが呼び出し対象の署名と一致しません。 ' –

+0

オプションのパラメータの周りに '{}'が必要かもしれませんが、ここでは私のTS制限に達しているようです。多分誰かが情報を提供することができます。 –

関連する問題