Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation Angular 2自定义验证程序运行两次_Validation_Angular - Fatal编程技术网

Validation Angular 2自定义验证程序运行两次

Validation Angular 2自定义验证程序运行两次,validation,angular,Validation,Angular,为了调试的目的,我使用了下面的代码。emailForCloudUserValidator在单个Ngonit运行上运行两次,并将两条消息记录到控制台 ngOnInit(){ this.contactControlGroup = this.formBuilder.group({ email:[this.contact.email, this.emailForCloudUserValidator] }); this.formControls = this.contactContro

为了调试的目的,我使用了下面的代码。emailForCloudUserValidator在单个Ngonit运行上运行两次,并将两条消息记录到控制台

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;
}

bootstrap()
之前调用
enableProdMode()
应该可以解决这个问题:

import {enableProdMode} from "angular2/core";

enableProdMode();

默认情况下,Angular2在
devMode
中运行,其中更改检测始终运行两次,以检查指示应用程序中存在错误的模型不稳定性(这会产生错误消息
表达式“xxxx”在检查后已更改

@misshap那么我猜这是对
null
的首次运行,然后当值更改为
this.contact.email
@misshap时再次运行。我还没试过。所以我什么都不能说。我说谢谢,因为我不知道这个信息。无法复制您的问题。你能提供一份详细的报告吗?