0

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

1
  • start by looking in browser console...the error angular is not defined would be a big clue....always check console first!! Commented Oct 1, 2016 at 17:43

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

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

9 Comments

What is the difference from the answer i posted?
Yours and mine is same ,I was few seconds later i think . Should I delete it ?
@Ujjwalkaushik no. This situation happens all the time, especially when answer is obvious and there is only one potential code change
@Ujjwalkaushik no, i was wondering if there is any difference! its ok to keep
ok @charlietfl ,but I should try to comment on these situations first :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.