2016-11-23 90 views
1

,我發現了錯誤:參數 'AccordionDemoCtrl' 不是一個函數,得到了不確定

Argument 'AccordionDemoCtrl' is not a function, got undefined.

我的JavaScript文件是:

angular.module('DatePicker', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']); 

angular.module('DatePicker').controller('DatepickerPopup', function ($scope) { 
    $scope.today = function() { 
     $scope.dt = new Date(); 
    }; 
    $scope.today(); 

    $scope.clear = function() { 
     $scope.dt = null; 
    }; 

    $scope.inlineOptions = { 
     customClass: getDayClass, 
     minDate: new Date(), 
     showWeeks: true 
    }; 

    $scope.dateOptions = { 
     dateDisabled: disabled, 
     formatYear: 'yy', 
     maxDate: new Date(2040, 5, 22), 
     minDate: new Date(), 
     startingDay: 1 
    }; 

    // Disable weekend selection 
    function disabled(data) { 
     var date = data.date, 
      mode = data.mode; 
     return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6); 
    } 

    $scope.toggleMin = function() { 
     $scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null : new Date(); 
     $scope.dateOptions.minDate = $scope.inlineOptions.minDate; 
    }; 

    $scope.toggleMin(); 

    //$scope.open1 = function() { 
    // $scope.popup1.opened = true; 
    //}; 

    $scope.open2 = function() { 
     $scope.popup2.opened = true; 
    }; 

    $scope.setDate = function (year, month, day) { 
     $scope.dt = new Date(year, month, day); 
    }; 

    //$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate']; 
    $scope.formats = ['dd-MMMM-yyyy']; 
    $scope.format = $scope.formats[0]; 
    //$scope.altInputFormats = ['M!/d!/yyyy']; 

    $scope.popup1 = { 
     opened: false 
    }; 

    $scope.popup2 = { 
     opened: false 
    }; 

    var tomorrow = new Date(); 
    tomorrow.setDate(tomorrow.getDate() + 1); 
    var afterTomorrow = new Date(); 
    afterTomorrow.setDate(tomorrow.getDate() + 1); 
    $scope.events = [ 
     { 
      date: tomorrow, 
      status: 'full' 
     }, 
     { 
      date: afterTomorrow, 
      status: 'partially' 
     } 
    ]; 

    function getDayClass(data) { 
     var date = data.date, 
      mode = data.mode; 
     if (mode === 'day') { 
      var dayToCheck = new Date(date).setHours(0, 0, 0, 0); 

      for (var i = 0; i < $scope.events.length; i++) { 
       var currentDay = new Date($scope.events[i].date).setHours(0, 0, 0, 0); 

       if (dayToCheck === currentDay) { 
        return $scope.events[i].status; 
       } 
      } 
     } 

     return ''; 
    } 
}); 
angular.module('DatePicker',[]).controller('AccordionDemoCtrl', function ($scope) { 
    $scope.oneAtATime = true; 

    $scope.groups = [ 
     { 
      title: 'Dynamic Group Header - 1', 
      content: 'Dynamic Group Body - 1' 
     }, 
     { 
      title: 'Dynamic Group Header - 2', 
      content: 'Dynamic Group Body - 2' 
     } 
    ]; 

    $scope.items = ['Item 1', 'Item 2', 'Item 3']; 

    $scope.addItem = function() { 
     var newItemNo = $scope.items.length + 1; 
     $scope.items.push('Item ' + newItemNo); 
    }; 

    $scope.status = { 
     isCustomHeaderOpen: false, 
     isFirstOpen: true, 
     isFirstDisabled: false 
    }; 
}); 

而我的HTML文件是:

<!DOCTYPE html> 
<html ng-app="lsApp.DatePicker"> 
<head> 
    <title></title> 
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script> 
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.2.0.js"></script> 
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">  
    <script src="Scripts/DatePicker.js"> 
</script> 

</head> 
<body> 

<div ng-controller="AccordionDemoCtrl"> 
    <script type="text/ng-template" id="group-template.html"> 
    <div class="panel panel-default"> 
     <div class="panel-heading"> 
     <h4 class="panel-title" style="color:#fa39c3"> 
      <a href tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" uib-accordion-transclude="heading"> 
      <span uib-accordion-header ng-class="{'text-muted': isDisabled}"> 
       {{heading}} 
      </span> 
      </a> 
     </h4> 
     </div> 
     <div class="panel-collapse collapse" uib-collapse="!isOpen"> 
     <div class="panel-body" style="text-align: right" ng-transclude></div> 
     </div> 
    </div> 
    </script> 

    <p> 
    <button type="button" class="btn btn-default btn-sm" ng-click="status.open = !status.open">Toggle last panel</button> 
    <button type="button" class="btn btn-default btn-sm" ng-click="status.isFirstDisabled = ! status.isFirstDisabled">Enable/Disable first panel</button> 
    </p> 

    <div class="checkbox"> 
    <label> 
     <input type="checkbox" ng-model="oneAtATime"> 
     Open only one at a time 
    </label> 
    </div> 
    <uib-accordion close-others="oneAtATime"> 
    <div uib-accordion-group class="panel-default" heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled"> 
     This content is straight in the template. 
    </div> 
    <div uib-accordion-group class="panel-default" heading="{{group.title}}" ng-repeat="group in groups"> 
     {{group.content}} 
    </div> 
    <div uib-accordion-group class="panel-default" heading="Dynamic Body Content"> 
     <p>The body of the uib-accordion group grows to fit the contents</p> 
     <button type="button" class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button> 
     <div ng-repeat="item in items">{{item}}</div> 
    </div> 
    <div uib-accordion-group class="panel-default" heading="Custom template" template-url="group-template.html"> 
     Hello 
    </div> 
    <div uib-accordion-group class="panel-default" is-open="status.isCustomHeaderOpen" template-url="group-template.html"> 
     <uib-accordion-heading> 
     Custom template with custom header template <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.isCustomHeaderOpen, 'glyphicon-chevron-right': !status.isCustomHeaderOpen}"></i> 
     </uib-accordion-heading> 
     World 
    </div> 
    <div uib-accordion-group class="panel-danger" heading="Delete account"> 
     <p>Please, to delete your account, click the button below</p> 
     <button class="btn btn-danger">Delete</button> 
    </div> 
    <div uib-accordion-group class="panel-default" is-open="status.open"> 
     <uib-accordion-heading> 
     I can have markup, too! <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i> 
     </uib-accordion-heading> 
     This is just some content to illustrate fancy headings. 
    </div> 
    </uib-accordion> 
</div> 
    </body> 
</html> 

我做錯了什麼?爲什麼我只在Google Chrome中收到錯誤?

回答

1

刪除括號,[]它應該是這樣的:

angular.module('DatePicker').controller('AccordionDemoCtrl', function ($scope) 
0

當你試圖聲明與模塊控制器沒有必要提及的depdencies,

變化

來源:

angular.module('DatePicker',[]).controller('AccordionDemoCtrl', function 

收件人:

angular.module('DatePicker').controller('AccordionDemoCtrl', function 
相關問題