• AnguglarJS error: Argument 'FirstCtrl' is not a function, got undefined

    MarkGrillo Member

    I just started learning a bit of programming. I’m following this tutorial:

    http://www.thinkster.io/pick/GtaQ0oMGIl/a-better-way-to-learn-angularjs
    

    But when I get at the section of Controllers and Sharing data between controllers, I cant get it to work.

    When I run it with Chrome, I get this error in the console:

    Error: [ng:areq] http://errors.angularjs.org/undefined/ng/areq?p0=FirstCtrl&p1=not%20a%20function%2C%20got%20undefined
        at Error (unknown source)
        at http://code.angularjs.org/1.2.0-rc.2/angular.min.js:6:453
        at qb (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:18:170)
        at Ia (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:18:257)
        at $get (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:58:137)
        at $get.f (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:46:383)
        at q (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:7:370)
        at l (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:46:274)
        at f (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:41:361)
        at f (http://code.angularjs.org/1.2.0-rc.2/angular.min.js:41:378)
    

    The link says ‘argument ‘FirstCtrl’ is not a function, got undefined’. I really don’t know what’s wrong. The code is the same from in the tutorial.

    Here is the code for the HTML I have:

    
    
     
        AngularJS Tutorials: Controllers
        
        
     
     
        

    {{data.message + " world"}}

    Wrap me in a foundation component

    And here is the code for the main.js:

    function FirstCtrl($scope){
       $scope.data = {message: "Hello"};
    }
    

    Hope someone can help me!!

  • Amit Member

    Change below should work

    to

    and the main.js to

    angular.module('myAppName', [])
        .controller('FirstCtrl', function($scope) {
         $scope.data = {message: "Hello"};
    });
    
Viewing 1 reply thread
  • You must be logged in to reply to this topic.
en_USEnglish