Joe Consterdine Joe Consterdine - 2 months ago 9
AngularJS Question

Angular not working but no errors

Following my code is not outputting the {{ title }} as

'hello world'
. Although angular is not working but gives no error message.

<!-- HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular</title>
</head>
<body np-app="myApp">
<div ng-controller="MainController">
{{ title }}
</div>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>`
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script type="text/javascript" src="angular.js"></script>
</body>
</html>


// Javascript

var app = angular.module("myApp", []);
app.controller("MainController", ['$scope', function($scope){
$scope.title = "hello world";
}]);

Answer

You have a typo in your body tag as <body np-app="myApp"> which needs to be changed to <body ng-app="myApp">

Hope this helps!