Manjula D Manjula D - 24 days ago 7
Javascript Question

Uncaught Error: [$injector:modulerr] and Uncaught Error: [$injector:nomod]

Hi I am beginner in Angular JS , when I start creating module and controller , I am unable to print my message, and below is my code



var myModule = angular.module("myFirst");

myModule.controller = ("cont", function($scope){
$scope.message = "Hi This is my first angular JS Learn ";
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="myFirst">
<head>
<title>This is Angular JS tutorial</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>

</head>
<body>
<div ng-controller="cont">
{{message}}
</div>

</body>
</html>




Can any one please explain , what is the issue caused ?

Thanks

Answer

You need to add empty dependencies

var myModule = angular.module("myFirst",[]);

Also controller should be,

myModule.controller("cont", function($scope){
   $scope.message = "Hi This is my first angular JS Learn ";
});

var myModule = angular.module("myFirst",[]);

myModule.controller("cont", function($scope){
$scope.message = "Hi This is my first angular JS Learn ";
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html  ng-app="myFirst">
<head>
<title>This is Angular JS tutorial</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>

	</head>
<body>
<div ng-controller="cont">
{{message}}
</div>

</body>
</html>