我想删除字母并只留下数字,验证很好,但输入视图没有正确更新。变量“数量”确实改变了它的值,我可以在下面显示它
<p> {{quantity}} </p>
按钮-add.component.html
<input
[ngModel]="quantity"
(ngModelChange)="quantity = changeQuantity($event)"
/>
<p> {{quantity}} </p>
按钮-add.component.ts
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'button-add-button',
templateUrl: './button-add.component.html',
styleUrls: ['./button-add.component.scss'],
})
export class ButtonAddComponent implements OnInit {
quantity: number = 10;
constructor() {}
public changeQuantity(cant: string) {
return parseInt(cant.replace(/[^0-9]+/g, ''));
}
}