1

enter image description here

Hi I am getting the following error:

Error : Cannot find module with name "my".

And also

Multiple annotations found at this line:-

Cannot find module with name my. Cannot find module with name my. Cannot find controller with name mycontroller

Please help. Thanks But I am able to run the code perfectly though the error exists.

My code is as below:

<!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> -->`
Penny Liu
  • 15,447
  • 5
  • 79
  • 98
user123
  • 259
  • 2
  • 6
  • 23
  • it worked for me https://jsbin.com/gujayadexa/edit?html,console,output – Zohaib Ijaz Feb 05 '16 at 22:59
  • Your code is not faulty at all. Have you tried resetting your cache? To play it safe, you should open your browser in incognito mode. We all know cache can be a killer. – JordyV Feb 06 '16 at 00:39
  • Hi,I have added the error image which I am getting "error_screenshot". I guess it's a configuration issue in eclipse. Please help. – user123 Feb 06 '16 at 01:35

1 Answers1

0

Try changing how your instantiating your controller. Try this:

<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>

Alternatively you could also instantiate it like this:

<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>

I have also added a JSFIDDLE that works both ways to show that they work

jsFiddle

Ohjay44
  • 897
  • 7
  • 20
  • @JordyV my first solution is done, take another look. Also the first solution is commonly used as well and both will work. – Ohjay44 Feb 05 '16 at 23:40
  • @JordyV to clarify further the first solution would be best if the controller was in a different JS file than the module. The second solution works best if it is in the same JS file. – Ohjay44 Feb 05 '16 at 23:42
  • @JordyV take a look again, they do work both of them. This is not a might work solution, this is a WILL work solution. I have provided a JSFiddle to prove my point with both controllers working! – Ohjay44 Feb 05 '16 at 23:55
  • == also works in JavaScript, but it's not the way it is meant to be used. This indeed works, but it is incorrectly used. It's not used as the creators intended. Don't use it that way. – JordyV Feb 05 '16 at 23:57
  • @JordyV what in the world are you talking about? First you criticize both controllers and I prove that they both work and now you bring up == and tell me that it is not meant to be used in a certain way. Are you sure you are commenting on the right thing. My answer is correct and fixes the issue and there is no == being used at all. == is also a perfectly fine way to compare as long as you are not wanting to compare on strict types. – Ohjay44 Feb 06 '16 at 00:00
  • @JordyV I think you are confused, please re-read the question and then read both of my solutions and realize that they both work and are the correct way of instantiating a controller in angular. – Ohjay44 Feb 06 '16 at 00:03
  • -sigh- Your first solution is indeed used when the controller and module are located in two different files. That is not the case here, so don't provide that 'answer', because it's not. I am using a metaphor to compare your first answer with other people who think == should be widely used in JavaScript. – JordyV Feb 06 '16 at 00:03
  • @JordyV again == is perfectly fine to use in Javascript and does not cause any issue unless you are wanting to compare on strict types. Also both of the solutions I provided work and are done correctly. There is no issue doing it either way it is just preference but it literally does not change the code or performance. The only exception is that the second solution does not work in a seperate js file for obvious reasons. – Ohjay44 Feb 06 '16 at 00:07
  • @JordyV For your convienence I have also provided a link to explain to you the difference between == and === which has nothing to do with this question. http://stackoverflow.com/questions/1094531/when-should-you-use-vs-vs-etc-in-javascript – Ohjay44 Feb 06 '16 at 00:10
  • Stop saying that, please.. That's like saying you can use a flat screwdriver to screw in a philips bolt.. It works, but it is not intended to be used that way. And that is the end of this conversation. God, some people.. – JordyV Feb 06 '16 at 00:10
  • @JordyV since I don't believe you will take the time to discover what == and === are used for: The == comparison operator always converts (to matching types) before comparison. (perfectly fine if you are not wanting strict types) The === operator forces comparison of values and type. – Ohjay44 Feb 06 '16 at 00:14
  • Hi,I have added the error image which I am getting "error_screenshot". I guess it's a configuration issue in eclipse. Please help. – user123 Feb 06 '16 at 21:59