我有一个输入框,我想在每次按键后验证输入。最终,当他们点击输入框外部时,我想要验证它(不确定使用哪个DOM事件)。问题是输入框“滞后”一个字符。
例如,如果用户输入“a”,那么它映射到的ngModel变量等于“”。当他们输入“ab”时,该变量等于“a”。
我做错了什么?
例如,如果用户输入“a”,那么它映射到的ngModel变量等于“”。当他们输入“ab”时,该变量等于“a”。
create-item.component.ts
的部分代码:export class CreateItem {
public item: Item;
constructor() {
this.item = new Item();
}
onCheckItemInput() {
// validate input on each keystroke
}
}
create-item.component.html的输入字段
<input class="form-control" type="text" required [(ngModel)]="item.name"
#spy pattern=".{3,255}" (input)="onCheckItemInput()">
我做错了什么?