我嘗試更新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'內的值。希望它可以幫助你... –