Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular.js:13708 Error: [ng:areq] Argument 'homeController' is not a function, got undefined

could not reach to homeController(module controller). while clicking on "home" link getting error on console that "homeController is not a function; undefined.

So, where i need to register this controller Thanks, Rahul

twoPageApp.js

 * Created by rahul on 9/24/2016.
 */
(function(){
        angular.module("twoPageApp",["ngRoute"])
            .config(function($routeProvider){
               $routeProvider
                   .when('/home',{
                      templateUrl:'/JS/twoPageAppJS/partials/home.html',
                      controller: 'homeController',
                      resolve:{
                           homeContent:['$http',function($http){
                               return $http.get('/homeContent.json');
                           }]
                       }
                   })
                   .when('/page_one',{
                        templateUrl:'/Js/twoPageAppJS/partials/pageOne.html',
                        controller:'pageOneController',
                        resolve:{
                            homeContent:['$http',function($http){
                                return $http.get('/pageOneContent.json');
                            }]
                        }
                   })
                   .when('/page_two',{
                       templateUrl:'/JS/twoPageAppJS/partials/pageTwo.html',
                       controller:'pageTwoController.js',
                       resolve:{
                           homeContent:['$http',function($http){
                               return $http.get('/pageTwoContent.json');
                           }]
                       }
                   })
            });
    })();

twoPageApp.Controller.js

       (function(){
    angular.module("twoPageApp").controller("tpaController",
        ['$scope',function($scope){
            $scope.name="this is twoPageApp js controller";
        }])
})();

module COntroller(homeController.js)

    /**
 * Created by rahul on 9/24/2016.
 */
(function(){
    angular.module("twoPageApp",[]) //here is the change...
        .controller("homeController",['$scope','$rootScope','homeContent',function($scope,$rootScope,homeContent){

            $rootScope.stub={
                homeContent:homeContent.data
            };
            $scope.hello="rahul";
            console.log("raja");
        }]);
})();

home.jsp

[![<div ng-app="twoPageApp" ng-controller="tpaController">
    <div>
        <a href="#/home">home</a>
        <a href="#/page_one">page One</a>
        <a href="#/page_two">page Two</a>
    </div>
    <div ng-view></div>
</div>][1]][1]
like image 819
Rahul Kumar Avatar asked Oct 30 '22 19:10

Rahul Kumar


1 Answers

Remove the [] parameter to the homeController registration inside homeController.js

angular.module("twoPageApp") // remove the [] parameter
like image 136
Merlin Avatar answered Nov 11 '22 04:11

Merlin