1

I have just started learning AngularJS but I am stuck at this point. I made three files in one project:

1.Index.html
2.Angular.min.js( downloaded from official site)
3.Script.js

But when I am opening html in browser I am not getting the value of test property. It just shows the {{test}} (not the value). Will be very thankful if you help me out.

 <!DOCTYPE html>
    <html lang="en" ng-app = "myapp">
    <head>
       <meta charset="UTF-8">
       <title>Document</title>
    </head>
    <body  ng-controller = "MyCtrl">
           {{test}}
           <script src = "angular.min.js"</script>
           <script src = "script.js"></script>
    </body>
    </html>***

Script.js file is

var app = angular.module('myapp',[]);

app.controller('MyCtrl', ['$scope', function($scope){
    $scope.test = "Welcome to my world";

}]);
5
  • I don't see any problem with code. Make sure the javascript files are being loaded correctly. Commented Aug 16, 2016 at 1:06
  • Check the developer tools (F12 in Chrome, Firefox and Opera) and see if the console displays any errors, because your code doesn't have any. Commented Aug 16, 2016 at 1:12
  • @GuranjanSingh: Yes it is loaded correctly, but no luck. Commented Aug 17, 2016 at 1:54
  • @Skaparate: console showing this error Uncaught Error: [$injector:modulerr], Commented Aug 17, 2016 at 1:55
  • 1
    @GagandeepSingh I'm certain the problem is with loading of the library. here is a plunker with the same code. Only difference is I'm loading the angular library from the google CDN and it works. Also, as mentioned in the answer you were missing > from the script tag where you include the library. That will cause it to break as well. Commented Aug 17, 2016 at 16:51

1 Answer 1

2

Check the network tab be sure angular itself is actually loading copying and pasting your code into a running sample.

var app = angular.module('myapp',[]);

app.controller('MyCtrl', ['$scope', function($scope){
    $scope.test = "Welcome to my world";

}]);
<!DOCTYPE html>
    <html lang="en" ng-app = "myapp">
    <head>
       <meta charset="UTF-8">
       <title>Document</title>
    </head>
    <body  ng-controller = "MyCtrl">
           {{test}}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
           <!--
           you were missing a > here
           <script src = "angular.min.js"</script>
           <script src = "script.js"></script>
-->
    </body>
    </html>

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

1 Comment

I did what you suggested, but no luck. Also, yes angular file has been loaded into my sample.

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.