Controller not a function, got undefined, while defining controllers globally

后端 未结 14 1806
感动是毒
感动是毒 2020-11-22 00:22

I am writing a sample application using angularjs. i got an error mentioned below on chrome browser.

Error is

Error: [ng:areq] http://errors.

14条回答
  •  走了就别回头了
    2020-11-22 00:40

    This error might also occur when you have a large project with many modules. Make sure that the app (module) used in you angular file is the same that you use in your template, in this example "thisApp".

    app.js

    angular
    .module('thisApp', [])
        .controller('ContactController', ['$scope', function ContactController($scope) {
            $scope.contacts = ["abcd@gmail.com", "abcd@yahoo.co.in"];
    
            $scope.add = function() {
                $scope.contacts.push($scope.newcontact);
                $scope.newcontact = "";
    
            };
        }]);
    

    index.html

      
        
                    
                    0
                  
                       
                    
                   讨论(0)
                  
                                                      
                  
                  
提交回复
热议问题