我尝试更新Angular 2中的输入值,它在大小值第一次超过maxSize时工作,但后续工作不再工作。当我将这个.size设置为某个值时,UI似乎没有更新,我可以忽略一些东西吗?Angular2模型绑定不起作用
HTML:
<input type="text" class="form-control" [value]="size" (input)="size = updateValue($event)">
代码:
export class BrushSizePicker {
@Input() minValue;
@Input() maxValue;
@Input() size;
increaseValue(event) {
this.size++;
this.checkValue();
}
decreaseValue(event) {
this.size--;
this.checkValue();
}
updateValue(event) {
this.size = parseInt(event.target.value);
this.checkValue();
return this.size;
}
private checkValue() {
if (this.size > this.maxValue) {
this.size = this.maxValue;
}
if (this.size < this.minValue) {
this.size = this.minValue;
}
}
编辑: 我登录了什么事:校验值时调用正确的输入每一次,它会返回正确的值。但新值未设置到输入字段/值字段中
当'maxValue'和'minValue'没有设置时'checkValue()'做什么?他们可能会重置为null。 –
你可以在'updateValue'方法中加入一些断点来查看它是否被调用,并查看'event.target.value'内的值。希望它可以帮助你... –