【问题标题】:Unable to get angular 2 form validation to work无法使 Angular 2 表单验证正常工作
【发布时间】:2016-09-21 20:35:56
【问题描述】:

我尝试通过 bwlow 教程在 Angular 2 中进行表单验证 https://angular.io/docs/ts/latest/guide/forms.html

但它只是返回一个空白页。

但是,如果我替换以下行

<form *ngIf="active" (ngSubmit)="onSubmit()" #heroForm="ngForm">

<form>

至少我得到了一些表单元素的出现。困难的部分是似乎没有错误消息可以引导我解决问题。

谁能帮忙?

【问题讨论】:

    标签: angular


    【解决方案1】:

    active 变量的状态是什么?一定是真的,因为你使用了 ngIf:

    <form *ngIf="active" (ngSubmit)="onSubmit()" #heroForm="ngForm">
    

    一切似乎都正常,但是您的表单只是没有呈现,因为 active 不存在/为假。

    【讨论】:

    • 组件类应该包含-public active = true;初始化 ngIf。它很容易被忽略,因为在响应式表单文档中没有提到它。
    猜你喜欢
    • 2020-04-24
    • 2012-11-18
    • 1970-01-01
    • 2012-04-22
    • 2012-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多