Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何使用角反应形式的电流管和验证器_Angular_Angular Reactive Forms_Angular Pipe - Fatal编程技术网

Angular 如何使用角反应形式的电流管和验证器

Angular 如何使用角反应形式的电流管和验证器,angular,angular-reactive-forms,angular-pipe,Angular,Angular Reactive Forms,Angular Pipe,我使用带有验证器的角度反应形式(值>0)。在我的模型中,我的数据是一个大十进制(例如5.80): 我使用货币管道: <input type="text" class="form-control" formControlName="money" [value]="userInfoFormGroup.get('money')?.value | currency:'EUR'"> 我的代码可以在网上找到 我的问题是原始值5.8被管道转换为5.8欧元。如何仅将管道用于显示而不用于模型 例

我使用带有验证器的角度反应形式(值>0)。在我的模型中,我的数据是一个大十进制(例如5.80):

我使用货币管道:

<input type="text" class="form-control" formControlName="money" [value]="userInfoFormGroup.get('money')?.value | currency:'EUR'">

我的代码可以在网上找到

我的问题是原始值5.8被管道转换为5.8欧元。如何仅将管道用于显示而不用于模型


例如,当我将5.8改为5.9时,我会重现这个问题。但我的应用程序更改了5.8欧元,更改了5.90欧元,我的validaror是KO,因为
是NaN。

你可以试一试:

<input type="text" class="form-control" formControlName="money" [value]="getNumberVal(userInfoFormGroup.get('money')?.value) | currency:'EUR'">

getNumberVal(val: string): number {
  val = `${val}`;
  return parseFloat(val.replace(/\u20AC/g, ''));
}

positiveVal(): ValidatorFn {
  return (control: AbstractControl): {[key: string]: any} | null => {
    const invalid = this.getNumberVal(control.value) <= 0;
    return invalid ? {'positiveVal': {value: control.value}} : null;
};

getNumberVal(val:string):数字{
val=`${val}`;
返回语法浮动(val.replace(/\u20AC/g',);
}
positiveVal():验证器fn{
return(control:AbstractControl):{[key:string]:any}| null=>{

const invalid=this.getNumberVal(control.value)您可以对此进行一次尝试:

<input type="text" class="form-control" formControlName="money" [value]="getNumberVal(userInfoFormGroup.get('money')?.value) | currency:'EUR'">

getNumberVal(val: string): number {
  val = `${val}`;
  return parseFloat(val.replace(/\u20AC/g, ''));
}

positiveVal(): ValidatorFn {
  return (control: AbstractControl): {[key: string]: any} | null => {
    const invalid = this.getNumberVal(control.value) <= 0;
    return invalid ? {'positiveVal': {value: control.value}} : null;
};

getNumberVal(val:string):数字{
val=`${val}`;
返回语法浮动(val.replace(/\u20AC/g',);
}
positiveVal():验证器fn{
return(control:AbstractControl):{[key:string]:any}| null=>{
const invalid=this.getNumberVal(control.value)