Michael Z Michael Z - 3 months ago 7
AngularJS Question

Simple AngularJS HelloWorld doesn't work

I'm newbie at AngularJS. Just wrote a simple Hello World to play with Angular. It seems it doesn't work and I can't understand why.

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Hello Angular World</title>
</head>
<body>

<h1 ng-controller="HelloWorldCtrl">{{HelloAngularWorld}}</h1>

<script src="angular.js"/>
<script type="text/javascript">
function HelloWorldCtrl($scope) {
$scope.HelloAngularWorld = "Hi World of Angular!";
}

</script>
</body>
</html>


Could you please point on my mistake?

Answer

Load AngularJS in the head and assign ng-app to one of the parents of the controller element (e.g. html or body so you get <html ng-app>).

See this example from their front page: http://angularjs.org/#add-some-control

Comments