angular.js:13708 Error: [ng:areq] Argument 'homeController' is not a function, got undefined
angular.js:13708 Error: [ng:areq] Argument 'homeController' is not a function, got undefined
无法访问 homeController(模块控制器)。
单击 "home" link 时在控制台上出现错误“homeController 不是函数;未定义。
所以,我需要在哪里注册这个控制器
谢谢,
拉胡尔
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";
}])
})();
控制器模块(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]
您必须像注册 tpaController
控制器一样注册 homeController
。
您已将 $routeProvider
设置为在 /home
url 上使用 homeController
,但您尚未在代码中的任何位置注册它。
去掉[]参数到homeController
注册里面homeController.js
angular.module("twoPageApp") // remove the [] parameter
无法访问 homeController(模块控制器)。 单击 "home" link 时在控制台上出现错误“homeController 不是函数;未定义。
所以,我需要在哪里注册这个控制器 谢谢, 拉胡尔
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";
}])
})();
控制器模块(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]
您必须像注册 tpaController
控制器一样注册 homeController
。
您已将 $routeProvider
设置为在 /home
url 上使用 homeController
,但您尚未在代码中的任何位置注册它。
去掉[]参数到homeController
注册里面homeController.js
angular.module("twoPageApp") // remove the [] parameter