gpt4 book ai didi

angularjs - 我怎样才能使默认 Accordion 打开第一个元素?

转载 作者:行者123 更新时间:2023-12-04 18:33:01 26 4
gpt4 key购买 nike

我在我的项目中使用 Bootstrap Accordion 。

这是工作fiddler .

这是HTML代码:

<div ng-app="myapp">
<div ng-controller="AccordionDemoCtrl">
<uib-accordion close-others="oneAtATime">
<uib-accordion-group ng-repeat="group in groups" is-open="isOpen">
<uib-accordion-heading>
<div class="text-center">
<strong>{{group.title}}</strong>
<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isOpen, 'glyphicon-chevron-right': !isOpen}"></i>
</div>
</uib-accordion-heading>
{{group.content}}</uib-accordion-group>
</uib-accordion>
</div>
</div>

这是 Controller :
var app = angular.module('myapp', ['ui.bootstrap', 'ngAnimate'])

app.controller('AccordionDemoCtrl', function($scope) {
$scope.groups = [{
title: "Dynamic Group Header - 1",
content: "Dynamic Group Body - 1"
}, {
title: "Dynamic Group Header - 2",
content: "Dynamic Group Body - 2"
}, {
title: "Dynamic Group Header - 3",
content: "Dynamic Group Body - 3"
}];
});

我尝试使用这一行:
  is-open="true"

像那样:
  <uib-accordion-group heading="{{group.title}}" ng-repeat="group in groups"  is-open="true">{{group.content}}</uib-accordion-group>

但它默认打开所有项目。

我怎样才能使默认 Accordion 只打开第一个元素?

附言这里更新 plunker

最佳答案

请使用$firstng-repeat指令只打开第一个 Accordion ,如 is-open="$first"
标记

<uib-accordion close-others="oneAtATime">
<uib-accordion-group heading="{{group.title}}"
ng-repeat="group in groups"
is-open="$first">
{{group.content}}
</uib-accordion-group>
</uib-accordion>

Preview Here

关于angularjs - 我怎样才能使默认 Accordion 打开第一个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37092876/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com