Angular.js: 13708 Error: [ng: areq] The argument 'homeController' is not a function, received undefined

Failed to get to homeController (module controller). when I click on the link "home" on the console, an error appears: "homeController is not a function, undefined.

So, when do 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"; }]) })(); 

COntroller module (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] 
+5
source share
2 answers

Extract parameter [] to register homeController inside homeController.js

 angular.module("twoPageApp") // remove the [] parameter 
+2
source

You need to register the homeController in the same way that you registered the tpaController . You set $routeProvider to use the homeController on /home URL, but you haven't registered it anywhere in the code.

0
source

All Articles