命名文本区域不在 angular 中的表单中创建实例

Naming textarea don't create instance in form in angular

我有这个使用 angular material 的模态对话框的 jade 模板(无法转换为 html,因为 jade site 不起作用):

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 over input 具有 name 属性的元素,它不会在 [=14] 中添加 name 属性 =] 表单对象。

您应该输入 ng-model="something" 以在 rejectionForm 表单中填充 reason