【发布时间】:2016-11-28 18:27:38
【问题描述】:
在我们的表单中,元素是使用 ng-repeat 动态创建的。 将表单值存储在 $scope.answers.[attribute name] 中。
以同样的方式,我想在表单提交时对更改应用验证。 但无法对动态元素调用验证。
我的 html 元素 (index.html)
<div ng-if="que.QuestionData._fieldType === 'text'" >
<text-control-dir data-que-obj="que.QuestionData" ></text-control-dir>
{{answers[que.QuestionData._attributeName]}}
<span ng-show="DTOstep1.answers[que.QuestionData._attributeName].$touched && DTOstep1.answers[que.QuestionData._attributeName].$invalid">The name is required.</span>
</div>
(controlDirectives.js) 指令具有用于表单控件的 html。 请参阅此 plunker 以获取完整代码。 https://plnkr.co/edit/GA74YHNFxFb0ARg16Sjj?p=preview
【问题讨论】:
-
你应该使用
ngForm指令。 -
我坚持在这里传递动态名称
标签: javascript jquery angularjs forms angular-formly