在Angular 7中,ngModelChange事件是在输入框的值发生改变时触发的。如果你的ngModelChange事件没有被触发,可能有以下几种原因:
onValueChange(event: any) {
console.log(event);
}
@Component({
...
})
export class MyComponent {
myValue: any;
onValueChange(event: any) {
console.log(event);
}
}
如果以上步骤都没有解决问题,你可以尝试使用ChangeDetectorRef来手动触发变更检测。
import { ChangeDetectorRef } from '@angular/core';
constructor(private cdr: ChangeDetectorRef) {}
onValueChange(event: any) {
console.log(event);
this.cdr.detectChanges();
}
希望以上解决方法能帮助到你解决Angular 7中ngModelChange事件不触发的问题。