Angular Bootstrap手风琴模板错误

时间:2015-07-27 18:43:07

标签: html angularjs twitter-bootstrap-3 accordion

我在发布问题之前进行了搜索,但找不到任何帮助。基本上,我使用Angular和Bootstrap与ui.angular.js。对于我这样的人来说,由于参考了accordion.html和accordion-group.html,基于我从开发工具中获得的错误,我无法使手风琴工作。

使用互联网上的一些快速帮助,我做了以下事情:

HTML:

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

  <label class="checkbox">
    <input type="checkbox" ng-model="oneAtATime">
    Open only one at a time
  </label>
  <accordion close-others="oneAtATime">
    <accordion-group heading="Static Header, initially expanded" is-open="status.isFirstOpen" is-disabled="status.isFirstDisabled">
      This content is straight in the template.
    </accordion-group>
    <accordion-group heading="{{group.title}}" ng-repeat="group in groups">
      {{group.content}}
    </accordion-group>
    <accordion-group heading="Dynamic Body Content">
      <p>The body of the accordion group grows to fit the contents</p>
        <button class="btn btn-default btn-sm" ng-click="addItem()">Add Item</button>
        <div ng-repeat="item in items">{{item}}</div>
    </accordion-group>
    <accordion-group is-open="status.open">
        <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>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>
  </accordion>
</div>

我的控制器中的javascript:

app.controller('pptController', ['$scope', 'pptService', function ($scope, pptService) {

    $scope.ppt = [];

    pptService.getPpt().then(function (results) {

        $scope.ppt = results.data;

    }, function (error) {
        //alert(error.data.message);
    });

  $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 = {
    isFirstOpen: true,
    isFirstDisabled: false
  };    

}]);

我在Chrome开发工具中遇到的错误:

enter image description here

我知道我在这里错过了一些东西,应该很简单。希望有人可以在这里快速帮助我!

非常感谢!

2 个答案:

答案 0 :(得分:1)

Angular Bootstrap使用独立的模板文件。确保您将ui-bootstrap-tpls.jsui-bootstrap.js文件一起包含。

你可以看到这是由ui-bootstrap没有模板引起的:

.directive('accordion', function () {
   return {
       restrict:'EA',
       controller:'AccordionController',
       transclude: true,
       replace: false,
       templateUrl: 'template/accordion/accordion.html'
    };
})

答案 1 :(得分:0)

似乎无法加载模板文件。确保您可以从浏览器中导航到文件http://localhost:9000/...../accordion.html ...

指定模板位置时很可能是拼写错误...