Answer the question
In order to leave comments, you need to log in
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
Try like this:
var demoApp = angular.module('demoApp', []);
demoApp.controller('DemoController', function($scope){
$scope.name = 'World';
});
Because angular.module('app', []).controller('DemoController', DemoController);
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 questionAsk a Question
731 491 924 answers to any question