1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
我能想到的幾種方法:
<input name="" ... (blur)="transform()" />
...
import { Component } from '@angular/core';
import { DecimalPipe } from '@angular/common';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
constructor(private decimalPipe: DecimalPipe) {}
decimal = "0";
transform() {
this.decimal = this.decimalPipe.transform(this.decimal, '1.2-2');
}
}
需要注意的是,轉(zhuǎn)換管道會(huì)返回一個(gè)字符串。我已經(jīng)寫了這個(gè)指令,我過(guò)去曾用于反應(yīng)式形式或這個(gè)模板
<input [value]="appform.budgetvalue | number: '1.2-2'"/>- 然而,這可能不是你期望的方式,但可能會(huì)給你一些想法
添加回答
舉報(bào)