Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 583
Nomad Avatar asked Dec 15 '22 03:12

Nomad


1 Answers

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

like image 190
Paul Samsotha Avatar answered Dec 16 '22 18:12

Paul Samsotha