我有一个这样的html:
<ng-template [ngSwitchCase]="'textbox'">
<input *ngIf="setting.type==='number'"
[step]="setting.step"
[formControlName]="formName"
[id]="formName"
[type]="setting.type"
[placeholder]="setting.placeholder"
[title]="setting.description"
(ngModelChange)="onChange($event)">
</ng-template>
在控制器上我有 onChange 函数:
onChange(newValue: string) {
if (newValue === undefined)
return;
this.form.get(this.formName).setValue(<any>parseFloat(newValue));
}
当我调试 onChange 函数的这个调用时,我注意到它仍在调用并且真的不知道为什么。我有一个无限循环。
我的角度包:
"@angular/animations": "8.2.7",
"@angular/cli": "8.3.5",
"@angular/common": "8.2.7",
"@angular/compiler": "8.2.7",
"@angular/core": "8.2.7",
"@angular/forms": "8.2.7",
"@angular/platform-browser": "8.2.7",
"@angular/platform-browser-dynamic": "8.2.7",
"@angular/router": "8.2.7",
"@babel/polyfill": "7.6.0",
您知道我的代码可能有什么问题吗?