【问题标题】:Property 'find' does not exist on type 'FormGroup'. any类型“FormGroup”上不存在属性“查找”。任何
【发布时间】:2017-01-29 17:52:27
【问题描述】:

我有简单的 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>

我正在尝试显示消息“无效电子邮件”是电子邮件提交未通过验证器,但收到此错误

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

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

【问题讨论】:

    标签: angular typescript angular2-forms


    【解决方案1】:

    find 已从 RC6 中的 AbstractControlFormGroup 的超类)中删除。你应该改用get

    【讨论】:

      【解决方案2】:

      我正在做一个角度课程,它有这样的线条:

      “!myForm.find('email').valid”和“!myForm.find(['userData','email']).valid”

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

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

      【讨论】:

      • 欢迎来到 Stack Overflow!如果您有新问题,请点击 按钮提出问题。如果您有足够的声誉,you may upvote 的问题。或者,将其“加星标”作为收藏夹,您将收到任何新答案的通知。
      猜你喜欢
      • 2019-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 2023-01-23
      相关资源
      最近更新 更多