Angularjs Argument 'controller' is not a Function, got Undefined

Asked

Viewed 1,730 times

0

Good night, you guys! I am beginner in Angularjs, I’m having the following problem

Error: [ng:areq] Argument 'smgoCtrl' is not a function, got undefined
http://errors.angularjs.org/1.5.5/ng/areq?p0=smgoCtrl&p1=not%20a%20function%2C%20got%20undefined
minErr/<@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:68:12
assertArg@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1880:1
assertArgFn@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1890:1
$controller@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:10091:9
setupControllers@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:9209:34
nodeLinkFn@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:9002:32
compositeLinkFn@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:8397:13
compositeLinkFn@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:8400:13
publicLinkFn@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:8277:30
bootstrapApply/<@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1751:11
$RootScopeProvider/this.$get</Scope.prototype.$eval@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:17229:16
$RootScopeProvider/this.$get</Scope.prototype.$apply@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:17329:20
bootstrapApply@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1749:9
invoke@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:4665:16
bootstrap/doBootstrap@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1747:1
bootstrap@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1767:1
angularInit@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:1652:5
@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:30863:5
trigger@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:3166:7
defaultHandlerWrapper@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:3456:3
createEventHandler/eventHandler@file:///C:/Users/Alair/Desktop/showmustgoon/lib/angular/angular.js:3444:9
" a

and here’s the code.

Index.html
<html ng-app="smgo">
<head>
    <meta charset="UTF-8">
    <title>Titulo</title>
    <link rel="stylesheet" type="text/css" href="lib/bootstrap/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/app.css">
    <script src="lib/angular/angular.js"></script>
    <script src="js/controller/smgoCtrl.js"></script>
    <script src="lib/angular/angular-messages.js"></script>
    <script src="js/app.js"></script>
    <script src="lib/angular/angular-locale_pt-br.js"></script>


</head>
<body ng-controller="smgoCtrl">
    <div class="jumbotron">
    {{message}}
    </div>
    <div ng-include="'view/footer.html'"></div>
</body>
</html>

app.js
angular.module("smgo", []);

controller.js
angular.module("smgo").controller("smgoCtrl", function($scope){
            $scope.message = "Hello!!";

        });
  • Good! The same error happened to me and the problem was that the controller js file was not in index.html. Thank you.

1 answer

2

You should include your controller files after setting the app, not before.

<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-locale_pt-br.js"></script>
<script src="lib/angular/angular-messages.js"></script>

<script src="js/app.js"></script>
<script src="js/controller/smgoCtrl.js"></script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.