D
D
dnazarko2015-01-14 17:26:32
JavaScript
dnazarko, 2015-01-14 17:26:32

AngularJs. Why swears at the controller?

I'm learning angular from this video tutorial https://www.youtube.com/watch?v=4uOzpLmR6ns I can't figure out what's wrong...
error: Error: [ng:areq] Argument 'DemoController' is not a function, got undefined
here is the code:

<!doctype html>
<html lang="en" ng-app>
<head>
  <meta charset="utf-8">
  <title>My HTML File</title>
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
  <link rel="stylesheet" href="css/app.css">
  <script src="bower_components/angular/angular.js"></script>

  <script type="text/javascript">
    var DemoController = function($scope) {
      $scope.name = "world";
    };
  </script>
</head>
<body>

  <p>Nothing here {{'yet' + '!'}}</p>
  <p>1 + 4 = {{1+4}}</p>

  <div ng-controller="DemoController">
    <p>name = {{name}}</p>
  </div>

</body>
</html>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nakhaev, 2015-09-08
@nakhaev

replaced in new versions
on the
and earned

I
Ildar, 2016-05-03
@vistoyn

Try like this:

var demoApp = angular.module('demoApp', []);
demoApp.controller('DemoController', function($scope){
  $scope.name = 'World';
});

and in html write ng-app='demoApp'
works for version 1.5.5

S
Sergey, 2015-01-14
Protko @Fesor

Because angular.module('app', []).controller('DemoController', DemoController);

V
vsvladimir, 2015-01-14
@vsvladimir

And if you replace var DemoController = function($scope) {}
with function DemoController($scope) {} will it work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question