【问题标题】:Formatting input values, but having difficilties with updating the model格式化输入值,但难以更新模型
【发布时间】:2015-08-17 14:07:24
【问题描述】:

我正在尝试解决格式化某些输入字段的问题。

当我输入值时,我希望模型在输入时更新,如下所示: 我输入 ex '1200000',我希望它显示在输入字段 '1.200.000' 中,并且模型应该更新为 1200000。

如果模型已经有值,我还希望字段预先格式化。 同样需要按百分比格式化,请see my example

  <div ng-controller="testController as testCtrl">

 {{ 'Model: ' + testCtrl.value1 }} 
 <input type="text" cr-numeric ng-model="testCtrl.value1" /> <br />

{{ 'Model: ' + testCtrl.value2 }} 
<input type="text" cr-numeric="interest_3_decimals" ng-model="testCtrl.value2" />

当我输入值时格式化工作正常,但是当模型已经有一个值时我不能让它工作,并且在我输入数据时相应地更新为值。

请任何人帮忙。

【问题讨论】:

    标签: angularjs number-formatting angular-directive


    【解决方案1】:

    如果你只需要在视图中格式化,你可以使用number过滤器;

    只是:

    Model: {{ testCtrl.value1 | number:2 }} 
    

    所以,在模型中你还是有原始价值的;

    【讨论】:

    猜你喜欢
    • 2016-10-09
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    相关资源
    最近更新 更多