Brent Nicolet Brent Nicolet - 1 year ago 74
AngularJS Question

Angular JS code is not working

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.


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


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


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

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

Answer Source

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,

    <div id="main_div" ng-app='my_ang_app' ng-controller='first_div'>
    <script type="text/javascript" src="//"></script>
    <script type="text/javascript" src="app.js"></script>
    <script type="text/javascript" src="core.js"></script>

Here is the working App

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download