当我使用函数绑定文本框上的数据时,Angular 2中的两种数据绑定不会发生



我正在尝试使用函数进行双向数据绑定。以下是我的代码。

<input type="text" id="txtCurrentPrice" class="traderviewTxtBox" [(value)]="numberFormat(23236448)">

我的功能是

numberFormat(x) {
            return x.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
    } 

我遇到以下错误。任何人都可以帮助。

Unhandled Promise rejection: Template parse errors:
Parser Error: Unexpected token '=' at column 23 in [numberFormat(23236448)=$event] in myComponent@241:101 ("<input type="text" id="txtCurrentPrice" class="traderviewTxtBox" [ERROR ->][(value)]="numberFormat(23236448)">
                                <!--<dx-text-box id="txtCurrentP"): myComponent@241:101

双向数据签名似乎是不可能的,因为函数是输出操作。

您可以通过删除括号来绑定 value 属性单向:

<input type="text" id="txtCurrentPrice" class="traderviewTxtBox" [value]="numberFormat(23236448)">

最新更新