angular.js:13708错误:[ng:areq]参数'homeController'不是函数,未定义

Rah*_*mar 5 javascript json angularjs angular-routing

无法访问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');
                           }]
                       }
                   })
            });
    })();
Run Code Online (Sandbox Code Playgroud)

twoPageApp.Controller.js

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

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");
        }]);
})();
Run Code Online (Sandbox Code Playgroud)

针对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]
Run Code Online (Sandbox Code Playgroud)

Mer*_*lin 2

homeController去掉注册里面的[]参数homeController.js

angular.module("twoPageApp") // remove the [] parameter
Run Code Online (Sandbox Code Playgroud)