Orkun Oz Orkun Oz - 1 month ago 7
Javascript Question

Error: [ng:areq] Argument 'angularJSCtrl' is not a function, got undefined

Can anyone tell me what's wrong with the code. Because I don't see anything missed. It was all working during the class. I'm quite new to javascript and angular.

I tried to check other threads with the same error but didn't help me to solve the issue.

index.html

<!DOCTYPE html>
<html ng-app="angularJS">
<head>
<script src="/bower_components/angular/angular.js"></script>
<script src="app.js"></script>
<script src="controller.js"></script>
</head>

<body>

{{"Type your name"}}

<div ng-controller="angularJSCtrl as kontrol">

<button ng-click ="kontrol.sayHello()"> Click here </button>
<input type="text" ng-model="kontrol.name">
<h3> All students list </h3>

<div ng-repeat="el in kontrol.studentObj">
<div ng-show="{{ el.age < 20 }}"> {{el}}</div>
</div>

<includer></includer>
<br>
{{ kontrol.price | currency}}
<br>
{{ kontrol.date | date}}

</div>





controller.js

(function () {
angular.module("angularJS")
.controller("angularJSCtrl", angularJSMethod);
.directive("directCtrl", directMethod);

function angularJSMethod(){
var vm = this;
vm.sayHello = sayHello;
vm.name = "Orkun";
vm.studentNames = ['John', 'Robbert', 'Adam'];
vm.studentObj = [{name: 'Orkun', age: 22}, {name: 'Bob', age: 18}];
vm.price = 2000;
vm.date = new Date();

function sayHello(){
alert("Welcome" + ' ' + vm.name)
}}

function directMethod(){
return {
restrict: 'E',
templateUrl: 'custom.html'
}
}

})();


app.js

(function () {
angular.module("angularJS", []);

})();

Answer

Actually, the problem is that you don't need semicolon:

    .controller("angularJSCtrl", angularJSMethod); <--- here
    .directive("directCtrl", directMethod);

Remove it and everything will work fine

Comments