gpt4 book ai didi

javascript - angular.js :13708 Error: [ng:areq] Argument 'homeController' is not a function, 未定义

转载 作者:搜寻专家 更新时间:2023-11-01 04:29:49 25 4
gpt4 key购买 nike

无法访问 homeController(模块 Controller )。单击“home”链接时,控制台出现错误“homeController 不是函数;未定义。

所以,我需要在哪里注册这个 Controller 谢谢, 拉胡尔

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]

最佳答案

去掉homeController.jshomeController注册的[]参数

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

关于javascript - angular.js :13708 Error: [ng:areq] Argument 'homeController' is not a function, 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39677279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com