Skip to content

Commit

Permalink
fix(module:form): fix form control validate with formControl
Browse files Browse the repository at this point in the history
close #3551
  • Loading branch information
vthinkxie authored and vthinkxie committed Jun 21, 2019
1 parent 10d0e28 commit bc54e90
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions components/form/nz-form-control.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
TemplateRef,
ViewEncapsulation
} from '@angular/core';
import { FormControl, FormControlName, NgControl, NgModel } from '@angular/forms';
import { FormControl, FormControlDirective, FormControlName, NgControl, NgModel } from '@angular/forms';
import { Subscription } from 'rxjs';
import { startWith } from 'rxjs/operators';

Expand Down Expand Up @@ -59,7 +59,7 @@ export class NzFormControlComponent extends NzColDirective
status: NzFormControlStatusType = null;
controlClassMap: NgClassType = {};
iconType: string;
@ContentChild(NgControl, { static: false }) defaultValidateControl: FormControlName;
@ContentChild(NgControl, { static: false }) defaultValidateControl: FormControlName | FormControlDirective;
@Input() nzSuccessTip: string | TemplateRef<{ $implicit: FormControl | NgModel }>;
@Input() nzWarningTip: string | TemplateRef<{ $implicit: FormControl | NgModel }>;
@Input() nzErrorTip: string | TemplateRef<{ $implicit: FormControl | NgModel }>;
Expand Down Expand Up @@ -194,8 +194,12 @@ export class NzFormControlComponent extends NzColDirective
}

ngAfterContentInit(): void {
if (this.defaultValidateControl && !this.validateControl && !this.validateString) {
this.nzValidateStatus = this.defaultValidateControl;
if (!this.validateControl && !this.validateString) {
if (this.defaultValidateControl instanceof FormControlDirective) {
this.nzValidateStatus = this.defaultValidateControl.control;
} else {
this.nzValidateStatus = this.defaultValidateControl;
}
}
}

Expand Down

0 comments on commit bc54e90

Please sign in to comment.