这个问题取决于你想要的实际效果。如果你想要在输入框内实时更新显示文字,可以使用 [(ngModel)] 双向绑定指令,例如:

<input type="number" [(ngModel)]="topUpCredit">
<p *ngIf="payMethodId!=3">
  {{'支付' | translate}}
  <b>{{(topUpCredit * (payMethodId == 2 ? 1.01 : 1.00)).toFixed(2)}}</b> {{'将实际到账' | translate}}
  <b>{{(topUpCredit * 1.00).toFixed(2)}} </b>
</p>

这样,每当用户在输入框中输入或修改数字时,相关的文本内容就会实时更新。如果你想要在用户点击输入框外的区域时更新文本内容,可以添加一个点击事件处理函数,例如:

<div (click)="updateText()">
  <p *ngIf="payMethodId!=3">
    {{'支付' | translate}}
    <b>{{(topUpCredit * (payMethodId == 2 ? 1.01 : 1.00)).toFixed(2)}}</b> {{'将实际到账' | translate}}
    <b>{{(topUpCredit * 1.00).toFixed(2)}} </b>
  </p>
</div>

然后在组件中添加一个 updateText 函数:

updateText() {
  // 触发 Angular 变更检测,更新文本内容
  this.cdRef.detectChanges();
}

这样,每当用户点击输入框外的区域时,updateText 函数就会触发 Angular 变更检测,强制更新文本内容。注意,这种方法可能会导致性能问题,因为它在每次点击时都会触发变更检测。如果你的页面很复杂或有很多这样的绑定,建议使用双向绑定来实现实时更新

p ngIf=payMethodId!=3 支付 translate btopUpCredit payMethodId == 2 101 100toFixed2b 将实际到账 translate btopUpCredit 100toFixed2 b p topUpCredit 被绑定到了一个输入框只有用户点击输入框外的区域topUpC

原文地址: https://www.cveoy.top/t/topic/fFzp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录