Deepak
Deepak

Reputation: 376

Angular JS Controller not working while using with .js file

I'm New to Angular JS. I'm trying a simple Example but it seemed to be not working.

I created a script.js with following code:-

var myApp = angular.module("myModule", []).controller("myController", function ($scope) { $scope.message = "AngularJS Tutorial"; });

And HtmlPage1.html :-

<script src="Script.js"></script>
 <script src="Scripts/angular.min.js"></script> </head> <body>
 <div ng-app="myModule">
     <div ng-controller="myController">
         {{ message }}
     </div>
 </div> 

But I'm getting this result:-

{{ message }}

I don't know what's wrong . Please Help...

Upvotes: 0

Views: 1119

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222722

Load Script.js after loading reference of angular.js, because your module declaration needs the reference of angular.

You need to do is make sure that the angular module is created before you attempt to register controller on it .

<script src="Scripts/angular.min.js"></script>  
<script src="Script.js"></script>

DEMO

Upvotes: 0

Ujjwal kaushik
Ujjwal kaushik

Reputation: 1686

<script src="Scripts/angular.min.js"></script>
<script src="Script.js"></script> </head> <body>
<div ng-app="myModule">
 <div ng-controller="myController">
     {{ message }}
 </div>
</div> 

Include controller after angular library (y)

Upvotes: 0

Related Questions