Recently, I started to learn AngularJS and decided to create my first AngularJS project. However, I faced the problem when initializing controller in html code.
I receive the following error:
angular.min.js:60 Error: Argument 'MainCTRL as ctrl' is not a function, got undefined
at qa (angular.min.js:16)
at ra (angular.min.js:16)
at angular.min.js:50
at angular.min.js:42
at m (angular.min.js:6)
at j (angular.min.js:42)
at e (angular.min.js:38)
at e (angular.min.js:38)
at e (angular.min.js:38)
at angular.min.js:37(anonymous function) @ angular.min.js:60(anonymous function) @ angular.min.js:51e.$apply @ angular.min.js:86(anonymous function) @ angular.min.js:15d @ angular.min.js:26qb @ angular.min.js:15kc @ angular.min.js:15(anonymous function) @ angular.min.js:158a @ angular.min.js:114(anonymous function) @ angular.min.js:23m @ angular.min.js:6c @ angular.min.js:22
I don't want to use $scope at this time, and want to proceed with this task with controller alias. With $scope it is working alright, however, I am very interested in solution of the problem in case of using "controller as" form
It's a part of the code, where the error exists:
<html lang="en" ng-app="blog">
<head>
<script src="template/assets/js/angular/angular.js"></script>
<script src="template/assets/js/controllers/app.js"></script>
<link rel="stylesheet" href="template/assets/template.css">
</head>
<main ng-controller="MainCTRL as ctrl">
<div class="stage">
<div class="prog-lang-container left">
<div class="prog-lang-container-inner">
<img class="prog-lang-img" src="#" alt="#">
<span class="prog-lang-name">
{{ctrl.name}}
</span>
</div>
</div>
...
</div>
</main>
...
</html>
It's my app.js file, it's very simple just now:
(function(){
var app = angular.module('blog',[]);
app.controller("MainCTRL", function(){
this.name = "TEST";
})
})()
May be I'm missing something in the code
ng-app
in your HTML somewhere?