2017-08-30 12 views
0

Angular 4先行コンポーネントに次のコードがあります。 FormGroupにFormControlがあり、これはHTMLに関連付けられており、完全に機能します。FormControl setValueが呼​​び出されたときにValueChangesイベントが発生しない

this.ProfileForm.controls["code"] 

私がテキストボックスを変更すると、valueChangesイベントが発生します。今度は、プログラムによって、formcontrol値を更新すると、valueChangesイベントは発生しません。 以下は、コードiの行です。

this.ProfileForm.controls["code"].setValue("someValue"); 

this.ProfileForm.controls["code"].valueChanges.subscribe(() => { 
      console.log("modified");},() => { console.log("error") },() => { console.log("completed") }); 

ご迷惑をおかけして申し訳ございません。

+0

あなたはフォームを再初期化していませんか? –

+0

はい、私は再初期化していません。 – Bhimisetty

+0

あなたは完全なソースコードを投稿できますか?別の場所からの部品だけでなく、 –

答えて

0

変更しますが、まだ購読されていない間、あなたのコードでは、値を変更しているので、それはsetValueの

this.ProfileForm.controls["code"].valueChanges.subscribe(() => { 
      console.log("modified");},() => { console.log("error") },() => { console.log("completed") }); 

this.ProfileForm.controls["code"].setValue("someValue"); 

第1およびサブスクライブします。

+0

コメントのように、コードの位置はあなたが言及した正しい位置です。 – Bhimisetty

+0

@Bhimisettyあなたはどういう意味ですか? –

+0

私のコードはこのようなものです.ProfileForm.controls ["code"] valueChanges.subscribe(()=> { console.log( "modified");} => {console.log( "error ")}、()=> {console.log(" completed ")}); this.ProfileForm.controls ["code"]。setValue( "someValue"); – Bhimisetty

関連する問題