命名textarea不要在form中创建实例

Naming textarea don't create instance in form in angular

本文关键字:创建 实例 form textarea 命名      更新时间:2023-09-26

我有这个翡翠模板模态对话框使用角材质(无法转换为html,因为翡翠网站不工作):

md-dialog(aria-label='Reject', ng-cloak='')
  form(name="rejectionForm")
    md-dialog-content
      .md-dialog-content
        h2.md-title Reject confirmation for
        div(ng-bind-html="vm.parent.task.label")
        div {{rejectionForm | json}}
        textarea(placeholder="Please provide a reason for rejection", name="reason", style="width: 530px; height: 75px", ng-required="true")
        div(ng-messages="rejectionForm.reason.$error")
          div(ng-message="required") You need to give the reason
    md-dialog-actions(layout="row")
      span(flex)
      md-button(ng-click="vm.parent.cancel()") CANCEL
      md-button.md-primary.md-raised(ng-click="vm.parent.reject()", ng-disabled="rejectionForm.$invalid") REJECT

它应该在rejectionForm中创建名为reason的表单字段实例,但结果json看起来像这样:

{
   "$error": {},
   "$name": "rejectionForm",
   "$dirty": false,
   "$pristine": true,
   "$valid": true,
   "$invalid": false,
   "$submitted": false

}

为什么没有reason,为什么我的表格没有验证?

除非ng-model/input元素具有name属性的形式,否则它不会在rejectionForm形式对象中添加name属性。

你应该把ng-model="something"得到reason得到填充在rejectionForm的形式。