2017-10-13 20 views
0

現在のアプリケーションでは、角度2の反応型アプローチを使用しています。私は多くの入力フィールドを持っている、私はサーバーから得たjsonにパッチを当てています。angle2でのパッチ適用時に制御値をフォームに適用する方法

私は表示中に値をフォーマットし、送信中に実際の値を送信する必要があるような要件があります。

例:入力通貨フィールドは、通貨タイプをコンマで区切る必要があり、送信は単なる数字です。

これをどのように達成できますか?

フォームコントロールに値と表示値の両方が必要です。 。

<input type="text" data-test="yearlyRevenue" formControlName="yearlyRevenue" [numberformat]="18" > 

    numberformat is my custom directive to format the data 

答えて

0

blog.ngconsultant.ioに例があります。

「キー」は、「ぼかし」と「フォーカス」が発生したときのホットリストを使用しています。 "変換"と "解析"の2つの機能がある場合

ngOnInit() { 
    this.el.value = this.transform(this.el.value); 
} 

@HostListener("focus", ["$event.target.value"]) 
onFocus(value) { 
    this.el.value = this.parse(value); // opossite of transform 
} 

@HostListener("blur", ["$event.target.value"]) 
    onBlur(value) { 
    this.el.value = this.transform(value); 
} 
関連する問題