【发布时间】:2019-11-28 12:23:51
【问题描述】:
我在一个垫子表单字段中输入了我的输入:
<mat-form-field style="padding-right: 10px;">
<input matInput type="text" [ngModel]="value | formatSize" (ngModelChange)="value=+$event";
placeholder="value" [ngModelOptions]="{standalone: true}">
</mat-form-field>
我的烟斗
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({name: 'formatSize'})
export class FormatSize implements PipeTransform {
transform(value: number) {
return value.toLocaleString();
}
}
我的目标是显示一个格式如下的值:
1000 -> 1000
10000 -> 10000
...
我的代码的问题是,当我输入一个大于 9999 的值时,它会在我的输入中显示 NaN,而我的值在我的组件中是 ǹull。
编辑:堆栈中的复制代码:https://stackblitz.com/edit/angular-7fxuqi?file=src/app/app.component.html
【问题讨论】: