0

I am a newbie to angular js and found a strange problem.I was not able to run the following code :

hello.html

<html ng-app>
<head>
 <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
  <script src="controller.js"></script>
</head>
<body>
  <div ng-controller='HelloController'>
    <p>{{greeting.text}}, World</p>
  </div>
</body>
</html>

controller.js

function HelloController($scope) {
  $scope.greeting = { text: 'Hello' };
}
Satpal
  • 132,252
  • 13
  • 159
  • 168
Rajeev Akotkar
  • 1,377
  • 4
  • 26
  • 46
  • 2
    http://stackoverflow.com/questions/26646941/getting-an-error-when-using-ng-controller-in-angularjs-ver-1-3-0/26647015#26647015 – Kalhan.Toress Sep 29 '15 at 10:02

2 Answers2

1

Angular 1.3+ no longer supports controller declaration on the global scope. Modify your code as

angular.module('app', [])
.controller('HelloController', function ($scope) {
    $scope.greeting = {
        text: 'hello'
    }
});
Satpal
  • 132,252
  • 13
  • 159
  • 168
1

You need to create a module for your controller, for example :

angular.module('myApp.controllers')
    .controller('HelloController', function ($scope) {
        $scope.greeting = { text: 'Hello' };
    }
});