我跟踪剥离的代码以进行调试。 emailForCloudUserValidator在单个NgOnInit运行时运行两次,将两条消息记录到控制台。
ngOnInit(){
this.contactControlGroup = this.formBuilder.group({
email:[this.contact.email, this.emailForCloudUserValidator]
});
this.formControls = this.contactControlGroup.controls;
}
private emailForCloudUserValidator(control: Control) : { [s: string]: boolean }{
if(!control.value){
console.log("email value is null");
}
return;
}
答案 0 :(得分:2)
在enableProdMode()
之前调用bootstrap()
应该修复它:
import {enableProdMode} from "angular2/core";
enableProdMode();
默认情况下,Angular2在devMode
中运行,其中更改检测始终运行两次,以检查指示应用程序中存在错误的模型不稳定性(产生错误消息Expression 'xxxx' was changed after it was checked
)