0

I have no idea why when I do an AngularJS tutorial that it doesn't work in my browser. I'm new to AngularJS. Any insights would be great. I have 3 files.

index.html:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>First Angular App</title>
        <script src="angular.js"></script>
        <script src="app.js"></script>
        <script src="core.js"></script>
    </head>
    <body>
      <div id="main_div" ng-app='my_ang_app' ng-controller='first_div'>
       {{message}}
      </div>
    </body>
    </html>

app.js:

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

core.js:

app.controller('first_div', function ($scope) {
     $scope.message="Hello world from angular";
    });

When I preview it in the browser it shows {{message}}

3
  • 1
    What are the errors in console? Commented Jul 21, 2016 at 0:41
  • Check your file paths. Commented Jul 21, 2016 at 0:55
  • Your Angular code and corresponding html are syntactically and semantically correct. The only things I can surmise that would be wrong are your file paths or file names. Commented Jul 21, 2016 at 1:25

2 Answers 2

1

Check whether the javascript files you refered are loaded correctly and its always better if you refer them after loading the view. Something like below,

  <body>
    <div id="main_div" ng-app='my_ang_app' ng-controller='first_div'>
    {{message}}
    </div>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>
    <script type="text/javascript" src="app.js"></script>
    <script type="text/javascript" src="core.js"></script>
    </body>

Here is the working App

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

1 Comment

I moved them to the bottom and its working now. Thanks!
0

I think your problem is that you are not linking to the proper javascript file paths. Try to inspect element to see if you have any 404 errors.

Comments

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.