我有一个使用 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
}
为什么没有原因
以及为什么我的表单没有经过验证?
最佳答案
除非你有ng-model
超过input
元素为 name
form 的属性,它不会添加 name
属性(property) rejectionForm
表单对象。
你应该输入ng-model="something"
获取reason
填充在 rejectionForm
内表格。
关于javascript - 命名文本区域不会以 Angular 形式创建实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39251403/