找不到名为“my”的模块。找不到名为'mycontroller'的控制器

时间:2016-02-05 22:51:37

标签: angularjs eclipse

enter image description here

您好我收到以下错误:

  

错误:找不到名为“my”的模块。

在此行找到多个注释: -

无法找到名称为my的模块。找不到名字我的模块。 找不到名为mycontroller的控制器

请帮忙。谢谢但是我能够完美地运行代码,尽管存在错误。

我的代码如下:

<!DOCTYPE html>
<html ng-app="my">
<head>
<script src="angular.js"></script>
<script>
    var validation = angular.module('my', []);
    validation.controller('mycontroller' , function($scope) {
        $scope.firstName = "madhuri";
        $scope.email = "madhuri@gmail.com";
        $scope.age = "24";
        $scope.pattern = /^\d*$/;
    });

</script>
</head>

<body >
    <div ng-controller="mycontroller">
        <form name="form1">
            <label>Name :</label> <input type="text" name="name" ng-model="firstName" required> 
            <span style="color: red" ng-show="form1.name.$error.required"> please provide the name</span> 
            <br> 
            <br> 
            <label>Email: </label> <input type="email"
                name="email" ng-model="email"> 
            <span style="color: red" ng-show="form1.email.$error.email"> please provide the valid email address </span>
             <p style= "color: red" ng-show="form1.email.$error.email">please provide the valid email address</p>


            <label>age :</label> 
            <input type="text" name="age" ng-model="age" ng-pattern="pattern">
             <span style="color: red" ng-show="form1.age.$error.pattern"> please provide the correct age
            </span>
        </form>
    </div>
</body>
</html> -->`

1 个答案:

答案 0 :(得分:0)

尝试更改实例化控制器的方式。试试这个:

<script>
var validation = angular.module('my', []);
angular.module('my').controller('mycontroller' , function($scope) {
    $scope.firstName = "madhuri";
    $scope.email = "madhuri@gmail.com";
    $scope.age = "24";
    $scope.pattern = /^\d*$/;
});
</script>

或者您也可以像这样实例化它:

<script>
var validation = angular.module('my', []).controller('mycontroller' , function($scope) {
    $scope.firstName = "madhuri";
    $scope.email = "madhuri@gmail.com";
    $scope.age = "24";
    $scope.pattern = /^\d*$/;
});
</script>

我还添加了一个JSFIDDLE,它可以通过两种方式显示它们的工作原理

jsFiddle