usrlog usrlog - 2 years ago 56
AngularJS Question

Argument (Controller) is not a function, got undefined

After googling for an hour and searching in Stackoverflow I cannot get the answer. I am new to angular and this is just a practice but i cannot make it work. I get this error in the console:


Error: Argument 'StoreController as store' is not a function, got
undefined.


The code:

<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>AngularJS</title>


</head>
<body>
<div ng-controller="StoreController as store">
<h2>{{store.employee.name}}</h2>
<h3>{{store.employee.age}}</h3>
</div>


<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script type="text/javascript"
src="app.js"></script>
</body>
</html>


app.js file:

(function() {
var app = angular.module('myApp', []);

app.controller('StoreController', function() {
this.employee = {
name: 'John',
age: 32
};
});

})();

Answer Source

Your Angular version is outdated. You're currently using 1.0.7. The controllerAs construct was only added in version 1.2. You should up your version to the latest.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download