[英]Angular JS error : “angular.js:13708 Error: [ng:areq] ”
[英]angular.js:13708 Error: [ng:areq] Argument 'homeController' is not a function, got undefined
無法訪問homeController(模塊控制器)。 點擊“home”鏈接獲取控制台上的錯誤“homeController不是一個函數;未定義。
那么,我需要注冊這個控制器謝謝,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]
刪除[]參數來homeController
內部登記homeController.js
angular.module("twoPageApp") // remove the [] parameter
您必須以注冊homeController
的方式注冊tpaController
。 您已設置$routeProvider
以在/home
url上使用homeController
,但您尚未在代碼中的任何位置注冊它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.