我在控制器中有这段代码
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
我怎么能想解决这个问题?谢谢你的帮助
答案 0 :(得分:0)
This error results from the $injector being unable to resolve a required dependency. To fix this, make sure the dependency is defined and spelled correctly. For example:
angular.module('myApp', [])
.controller('MyController', ['myService', function (myService) {
// Do something with myService
}]);
The above code will fail with $injector:unpr if myService is not defined.
Making sure each dependency is defined will fix the problem, as noted below.
angular.module('myApp', [])
.service('myService', function () { /* ... */ })
.controller('MyController', ['myService', function (myService) {
// Do something with myService
}]);
so for your part, try:
app.controller('Ctrl', ['$scope','$invalid','$location',function($scope,$invalid, $location)
{}];