-3

I'm trying to learn AngularJS and the first example I have tried does not work. Why? Here is the HTML:

<html ng-app>
<head>
    <title></title>
    <script src="Scripts/angular.js"></script>
    <script src="app.js"></script>    
</head>``
<body ng-controller="MainCtrl">
    <div>Hello, {{userGroup.name}}!</div>
</body>
</html>

And here is the javascript (app.js file) code:

var MainCtrl = function ($scope) {
   $scope.userGroup = {
      name: "Kirill Kuts"
   };
}
Reid Spencer
  • 2,776
  • 28
  • 37
bati
  • 3
  • 2
  • What is the error? and what version of angular? – PSL Jan 17 '15 at 20:30
  • I don't think your HTML is valid, it has `` in it between and . Beyond that, we'd need to see the error message or some description of "does not work" in order to answer. – Reid Spencer Jan 17 '15 at 20:36
  • Most probably you're using a recent AngularJS version. New versions does not support controller definitions this way. – Ertunç Jan 17 '15 at 20:42

1 Answers1

0
  1. I would start by rewriting your controller. From AngularJS 1.3 onwards global controllers are disabled, refer:

$controller: disable using global controller constructors (3f2232b5)

  1. Register a new angular module - with a name.
angular.module('app', [])
  .controller('MainCtrl', function ($scope) {
   $scope.userGroup = {
      name: "Kirill Kuts"
   };
});
  1. update ng-app directive


Here is a working demo - http://jsbin.com/mufifukuvu/1/edit?html,js,output

Michael Coleman
  • 3,288
  • 3
  • 19
  • 18
  • thank u guys, looks like that's stupid mistake. yeah, the lesson I watched is 1 year old – bati Jan 17 '15 at 20:54