在模态 Controller 中,我正在尝试像这样设置验证器:
$scope.taskForm.start_date.$setValidity("date", false);
这是我的 html:
<input name="start_date" id="startdate" ng-model="modal.project.startDate" type="date" class="form-control" required/>
<!--VALIDATION-->
<span ng-show="taskForm.start_date.date">Something</span>
但这不起作用,我认为这是因为模态。
我也在控制台中收到此错误:
TypeError: Cannot read property 'start_date' of undefined
编辑:
这是问题所在的示例,只需取消模态 Controller 中的注释行,然后查看控制台中的问题所在:
http://jsfiddle.net/9tasz57s/
最佳答案
它更有可能与这个错误有关 https://github.com/angular-ui/bootstrap/issues/969
尝试将 ui-bootstrap 升级到最新的 greatest 版本,看看问题是否仍然存在。如果您无法升级,那么在 github 的问题中,您会找到针对此问题的几种解决方法。喜欢https://github.com/9ci/angle-grinder/commit/a3a1bc4483e01eb235d13f29709d2fd2604a8ddc#L4R28
关于angularjs - 模态 Controller 中的 $setValidity [AngularJS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34074219/