【问题标题】:disabled property of button binding not working angular 4 [duplicate]按钮绑定的禁用属性不起作用角度4 [重复]
【发布时间】:2018-01-11 19:02:38
【问题描述】:

我对我的语法很好奇。

根据我在网上找到的文档和示例,如果我的表单无效,我的表单中的按钮应该被禁用。但是,buttons disabled 属性不受我的表单 css 逻辑的影响。

html:

 <form (ngSubmit)="addcity()" #cityform ="ngForm">
      <input type="text"
             placeholder="add a city"
             id="cityadd"
             name="cityadd"
             ngModel
             pattern="([A-Z][a-z]*(\s[A-Z][a-z]*)*)"
             #formcitycss ="ngModel">
      <button type="submit" [disabled]="!formcitycss.valid" >Add City</button>
    </form>

这应该有效,但事实并非如此。就语法而言,我做错了什么,因为我觉得自己很准确

【问题讨论】:

  • 根据this answer,应该是[disabled]="!cityform.form.valid"

标签: angular validation angular-forms property-binding


【解决方案1】:

尝试将其绑定到实际表单而不是单个输入。

[disabled]="! cityform.valid"

【讨论】:

    【解决方案2】:

    使用表单名称

     <button type="submit" [disabled]="!cityform .valid" >Add City</button>
    

    【讨论】:

      【解决方案3】:

      所以他们都没有工作。我超过了。我刚刚为 dom 创建了一个 If 语句,以在表单有效且被触摸时显示按钮。

      【讨论】:

        猜你喜欢
        • 2018-04-11
        • 1970-01-01
        • 2018-03-04
        • 1970-01-01
        • 2013-12-07
        • 2016-05-07
        • 1970-01-01
        • 2017-08-28
        • 2020-10-14
        相关资源
        最近更新 更多