Yassine Boutabia Yassine Boutabia - 2 months ago 8
AngularJS Question

Basic Angularjs code not runing?

I using very simple code. I seem to be missing something that does run the Angularjs code.

here is my html code:

<html>
<head>
<title></title>
</head>
<body ng-app="myAppApp">
<div ng-controller="exempleCtrl">
HELLO {{name}}!
</div>
</body>
</html>


Here is app.js code:

var app = angular.module('myAppApp',[]);
app.controller('exempleCtrl', function($scope) {
$scope.name = 'World';
});


I'm new to Angularjs. So I could be missing something big here.

Answer

The issue, as pointed out in the comments, is that you did not include your Javascript code in the HTML file. So assuming you called it something like app.js and is in the same directory as the HTML file, then you need to include it as follows:

 <html>
<head>
    <title></title>
    <!-- You should also add reference to angular (use desired version - example here is 1.2.4) -->        
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script>
    <!-- Here including the app.js-->
    <script src="app.js"></script>
</head>
<body ng-app="myAppApp">
<div ng-controller="exempleCtrl">
   HELLO {{name}}!
</div>
</body>
</html>

Give it a try and let us know if this works.