dnazarko2015-01-14 17:26:32
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>
  <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";

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

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


Answer the question

In order to leave comments, you need to log in

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

replaced in new versions
on the
and earned

Ildar, 2016-05-03

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

Sergey, 2015-01-14
Protko @Fesor

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

vsvladimir, 2015-01-14

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