货币掩码(Angular)在没有直接输入的情况下无效

时间:2018-03-09 10:24:47

标签: angular currency mask

我有几个输入字段(数字),是最后一个(禁用)它们是求和或减法的结果。所有这些都有货币掩码,包括总字段。问题是填充它们时,总字段不会采用小数,只有在我启用它时,键入一个数字。然后出现小数。有人可以帮忙解决问题吗?

HTML:

 <div class="row">
              <div class="col-md-4">
                <input [(ngModel)]="mainBudget.budget.own_resources" class="form-control" placeholder="{{dataResources.placeholder.euro}}"
                  type="text" currencyMask required>
              </div>
            </div>
            <div class="row">
              <div class="col-md-4">
                <input [(ngModel)]="mainBudget.budget.revenues_generated_by_project" class="form-control" type="text" currencyMask placeholder="{{dataResources.placeholder.euro}}"
                  required>
              </div>
            </div>

 <div class="row">
              <div class="col-md-4">
                <input class="form-control disabled" disabled  type="text" currencyMask [value]="totalBudget()" placeholder="{{dataResources.placeholder.euro}}"
                  required>
              </div>
            </div>

总和方法:

 totalBudget(): number {
        return this.mainBudget.budget.own_resources +
          this.mainBudget.budget.revenues_generated_by_project;

      }

2 个答案:

答案 0 :(得分:0)

将此函数totalBudget()添加到

ngOnInit(){}或在里面添加:

setInterval(()=&gt; {this.totalBudget();},500);

答案 1 :(得分:0)

我使用了ngModel,就像这样:

TS

total:number;

 totalBudget(): boolean{
        this.total = this.mainBudget.budget.own_resources +
          this.mainBudget.budget.revenues_generated_by_project;
        return true ;
      }

HTML

<div class="row">
              <div class="col-md-4" *ngIf="totalBudget()"> 
                <input class="form-control"  type="text" disabled currencyMask [(ngModel)]="total"
                  required>
              </div>
            </div>