0

嗨,我在将控制器重构为自己的片段时遇到了一些问题

我希望控制器从我的初始应用程序声明中继承依赖项。

    "use strict";
    angular.module('clockOn', ['angular-contextual-date','logon','milli','mobile','ClockOnController','Auth','ngStorage'])

我需要这些依赖项流经我的控制器。

      angular.module('clockOn').controller('LogonController',              ['$rootScope','$scope','$location','$localStorage','Auth', 
function($rootScope, $scope, $location, $localStorage,Auth){ 

创建未知的提供程序错误——我假设依赖项没有向下流动——

    angular.module('clockOn',[]).controller() 

创建未定义的函数“控制器名称”错误-在这种情况下,我假设我正在重新定义应用程序并因此失去其他控制器-

这是两个控制器

(function (){
angular.module('clockOn',['Auth','angular-contextual-date'])  
.controller('ClockOnController',     ['$http','Auth','contextualDateService' ,function      ($http,Auth,contextualDateService){
      this.user = Auth.getTokenClaims().user; //authorised is a property of the controller 
      contextualDateService.config.fullDateFormats.thisMonth = "MMM d 'at'  h:mm a ";    
      this.shifts = getShifts(this);

    function getShifts(clockOnCtrl){
      var date = new Date();
      var curr_date = Date.now();
      var week_from_now = Date.now()+"7";

    $http({
      method: 'GET', 
      url: '/shifts', 
      params: {"user_id":clockOnCtrl.user._id,
      "start_at":curr_date,
      "finish_at":week_from_now} 
   }).
   then(function(res){           
     if (typeof res !== 'undefined'){
       console.log(res.data);
       clockOnCtrl.shifts = res.data;         
   }},
   function(error){
     console.log(error)
   });  
}

}]);
})();

我的索引文件

    <!DOCTYPE html>
    <html class="container" ng-app="clockOn"> <!-- ng-app tells the html page which app/module it belongs too runs the store module on load-->
    <head>
      <meta name="viewport" content="width=device-width , initial-scale=1">
      <link rel="stylesheet" type="text/css" href="../resources/bootstrap.min.css"/>
      <link rel="stylesheet" type="text/css" href="../resources/custom.css"/>
    </head>

    <body>  
      <script type="text/javascript" src="../resources/jquery.min.js"></script>    
      <script type="text/javascript" src="../resources/angular.min.js"></script>
      <script type="text/javascript" src="../resources/bower_components/angular-contextual-date/dist/angular-contextual-date.js"></script>     
      <script type="text/javascript" src="../modules/app.js"></script>       
      <script type="text/javascript" src="../modules/logon.js"></script>
      <script type="text/javascript" src="../modules/tasks.js"></script>
      <script type="text/javascript" src="../services/milli.js"></script>
      <script type="text/javascript" src="../services/auth.js"></script>
      <script type="text/javascript" src="../modules/mobile.js"></script>
      <script type="text/javascript" src="../modules/shifts.js"></script>
      <script type="text/javascript" src="../modules/layout-components.js"></script>
      <script type="text/javascript" src="../resources/bower_components/ngstorage/ngStorage.min.js"></script>    
      <script type="text/javascript" src="../controllers/controller-clockOn.js"></script>
      <script type="text/javascript" src="../controllers/controller-logon.js"></script>    
      <script type="text/javascript" src="../controllers/controller-tasks.js"></script> 

<div class="container" ng-controller="ClockOnController as clockOnCtrl">
  <div class= "" ng-controller="LogonController as logonCtrl">
  <logon-form></logon-form>
  <top-menu></top-menu>    
  <div class="page-header" ng-show="token">
    <h2 class="">Welcome {{clockOnCtrl.user.name | uppercase}}
      <small>You currently have {{clockOnCtrl.shifts.length}} shifts</small>
    <h2>
  </div>
  <shifts-list></shifts-list>
  <custom-footer></custom-footer> 
  </div>
</div>
</body> 
</html>

错误参数“ClockOnController”不是函数,未定义

4

0 回答 0