属性 'find' 在类型 'FormGroup' 上不存在。任何

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

我有简单的angular下面是2个表单代码

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

我正在尝试显示消息 "invalid email" 是电子邮件提交未通过验证程序,但出现此错误

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

我正在使用 angular 2 的最终版本。有什么想法吗?

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

我正在上 angular 课程,它有这样几行:

"!myForm.find('email').有效"和"!myForm.find(['userData','email']).有效"

似乎find不再在AbstractControl中,被get取代了。

将find替换为get其余保持原样。