2013-09-24 65 views
1

我試圖用AngularJS的$ routeprovider和requireJS時注入的控制器到$ routeScopeAngularJS控制器決心:參數「控制器」不是一個函數,得到了對象

$routeProvider.when '/', 
     templateUrl : loadView('aboutJellyfish') 
     controller: 'aboutJellyfish' 
     resolve: 
      first:loadController('aboutJellyfish') 

的loadController功能:

loadController = (ctrl_name) -> 
     resolve = undefined 
     resolve = ["$q", "$controller", "$rootScope", "$routeParams", ($q, $controller, $rootScope) -> 
      deferred = undefined 
      deferred = $q.defer() 
      require(["../controllers/" + ctrl_name], (ctrl_module) -> 
      $controllerProvider.register(ctrl_name, ctrl_module) 
      $rootScope.$apply(-> 
       deferred.resolve not 0 
      ) 
     ) 
      deferred.promise 
     ] 

的requirejs配置:

require.config 
    paths: 
    jQuery: 'lib/jQuery/jquery-1.10.2.min' 
    angular: 'lib/angular/angular.min' 
    app: 'app' 

    shim: 
    'angular': 
     exports : 'angular' 
     deps:['jQuery'] 
    'app': 
     deps:['angular'] 
     exports:'app' 
    'jQuery': 
     exports : '$' 

    priority: ['jQuery','angular','app'] 
    urlArgs: 'v=1.01' 

require ['angular','app'], (angular) -> 
    angular.element(document).ready() -> 
    angular.bootstrap(document,[applicationName]) 

並且所述控制器

的問題是,我得到以下錯誤「參數‘aboutJellyfish’不是一個函數,使用下面的一段在控制器的一切代碼得到Object'but正常工作:

'use strict' 
define ['app'],(app) -> 
    aboutJellyfish = ["$scope", ($scope) -> 
    $scope.info="Jellyfish Beta 0.1" 
    ] 

回答

1

loadController('aboutJellyfish')$routeProvider需要返回實際控制對象

return resolve = [ "$q", "$controller", "$rootScope", "$routeParams", function($q, $controller, $rootScope)... 

resolve {}接收函數。

resolve: { 
    first: <- it needs to be a function here 
} 
相關問題