0

I am learning angularJS, ng-app works ng-model works, but when I try ng-controller, it does not work, the fault is on my side but I am unable to figure out what it is, I am not even trying anything fancy, just trying make the ng-controller work,

what is my mistake in the below code?

HTML :

<div ng-app="">
    <h1 ng-controller="HelloWorldCtrl">{{helloMessage}}</h1>
</div>`

and JS :

function HelloWorldCtrl($scope){
    $scope.helloMessage="Hello World";
}

same problem when run in jsfiddle

mido
  • 24,198
  • 15
  • 92
  • 117
  • http://stackoverflow.com/questions/26646941/getting-an-error-when-using-ng-controller-in-angularjs-ver-1-3-0/26647015#26647015 – Kalhan.Toress Dec 07 '14 at 15:20

1 Answers1

3

var myapp = angular.module('myApp', []);

myapp.controller('HelloWorldCtrl', function($scope){
  $scope.helloMessage = "Hello world";

})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
    <h1 ng-controller="HelloWorldCtrl">{{helloMessage}}</h1>
</div>
Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133