【发布时间】:2016-09-01 02:32:26
【问题描述】:
我在控制器中有这段代码
app.controller('Ctrl', function($scope, $invalid, $location) {
$scope.upd_check = function()
{
console.log($scope.MyForm);
if($scope.MyForm.$invalid){
$("#modal_traffic_incorrect").modal('show');
}
}
我的html代码是
<form name="MyForm">
<div class="item_title">Text</div>
<div class="item_contentbox">
<input class="inputs len_md" name="number" ng-model="text" ng-required ng-pattern="/^([1-9])$/" >
</div><br />
<div class="col-md-offset-1 col-md-10 col-sm-12 text_right">
<button type="submit" class="button" ng-click="upd_check()">Save</button><br><br><br>
</div>
</form>
</div><br />
我收到此错误:错误:[$injector:unpr] http://errors.angularjs.org/1.4.8/$injector/unpr?p0=NaNnvalidProvider%20%3C-%20%24invalid%20%3C-%20Ctrl
我该如何解决这个问题?感谢您的帮助
【问题讨论】:
-
你的
MyForm在哪里?也可以放html吗?你应该试试$valid然后$invalid -
@ParthTrivedi 我刚刚编辑了我的问题
-
尝试从
Controller中删除$invalid并使用if(!$scope.MyForm.$invalid) -
您不需要注入
$invalid或$valid。直接使用。 -
它显示错误 TypeError: Cannot read property '$invalid' of undefined when I try that @ParthTrivedi
标签: angularjs error-handling controllers