diff --git a/components/input-number/nz-input-number.component.ts b/components/input-number/nz-input-number.component.ts index f917774a2c2..4657bc33ef4 100644 --- a/components/input-number/nz-input-number.component.ts +++ b/components/input-number/nz-input-number.component.ts @@ -68,6 +68,7 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn private _step = 1; private autoStepTimer; private _autoFocus = false; + private _formatter = (value) => value; displayValue: string | number; actualValue: string | number; isFocused = false; @@ -82,7 +83,6 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn @Input() nzSize: 'small' | 'default' | 'large' = 'default'; @Input() nzMin: number = -Infinity; @Input() nzMax: number = Infinity; - @Input() nzFormatter = (value) => value; @Input() nzParser = (value) => value; @Input() nzPrecision: number; @@ -125,6 +125,16 @@ export class NzInputNumberComponent implements ControlValueAccessor, AfterViewIn return this._step; } + @Input() + set nzFormatter(v: (value: number) => string | number) { + this._formatter = v; + this.writeValue(Number(this.actualValue)); + } + + get nzFormatter(): (value: number) => string | number { + return this._formatter; + } + updateAutoFocus(): void { if (this.isInit) { if (this.nzAutoFocus) {