Nomad Nomad - 2 months ago 32
AngularJS Question

Property 'find' does not exist on type 'FormGroup'. any

I have simple angular 2 form code is below

<form [formGroup]="myForm" (ngSubmit)="onSubmit()" class="formcss">
Username<br>
<input type="text" formControlName="username"><br><br>
<div>
Email<br>
<input id="email" type="text" formControlName="email">
<div *ngIf="myForm.find('email').valid">Invalid Email</div><br><br>
Password<br>
</div>
<input type="text" formControlName="password"><br><br>
<h3>Hobbies</h3>
<input type="text"><br><br>

<button>Add Hobby</button>
<button type="submit" [ngStyle]="{ background:'green'}" [disabled]="!myForm.valid">Submit</button>
</form>


I am trying to show message "invalid email" is email filed does not pass validator, but getting this error

error_handler.js:45 EXCEPTION: self.context.myForm.find is not a function


I am using final release of angular 2. Any idea?

Answer

find was removed from AbstractControl (super class of FormGroup) in RC6. You should use get instead