简体   繁体   English

Angular UI Bootstrap手风琴-未打开第一个手风琴组

[英]Angular UI Bootstrap Accordion - First accordion group is not opened

I am using UI-Bootstrap Accordion and populating content from JSON Object. 我正在使用UI-Bootstrap手风琴,并从JSON对象填充内容。 Now i am trying to open first accordion group always on load but its not working. 现在,我正在尝试打开始终处于加载状态的第一个手风琴组,但它无法正常工作。

I have used is-open setting as true but still not working. 我已将is-open设置设为true,但仍无法正常工作。 Please see below plunker for refrence. 请参阅下面的缩略语以获取参考。

Plunker 柱塞

<uib-accordion close-others="oneAtATime">
        <uib-accordion-group ng-repeat="faq in FAQs" is-open="this.open">
            <uib-accordion-heading>
                <div>{{faq.title}}<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-up': this.open, 'glyphicon-chevron-down': !this.open}"></i>
                </div>
            </uib-accordion-heading>
            <div  ng-bind-html="faq.content"></div>
        </uib-accordion-group>
        </uib-accordion>

Thanks, 谢谢,

Angular having some inbuilt Variables in ng-repeat $index (0..length-1), $first,$middle,$last,$even,$odd this variables can help you to play easy :-) Angular在ng-repeat $index (0..length-1), $first,$middle,$last,$even,$odd有一些内置变量,这些变量可以帮助您轻松玩:-)

refer :- https://docs.angularjs.org/api/ng/directive/ngRepeat for further information . 请参阅: -https : //docs.angularjs.org/api/ng/directive/ngRepeat了解更多信息。

According to your expected output you just need to use $first in your is.open 根据您的预期输出,您只需要在is.open使用$first is.open

<uib-accordion close-others="oneAtATime" ng-repeat="faq in FAQs"> 
            <uib-accordion-group   is-open="$first">
                <uib-accordion-heading>
                    <div>{{faq.title}}<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-up': this.open, 'glyphicon-chevron-down': !this.open}"></i>
                    </div>
                </uib-accordion-heading>

                <div  ng-bind-html="faq.content"></div>
            </uib-accordion-group>
             <uib-accordion-group   ng-if="!$first" is-open="false">
                <uib-accordion-heading>
                    <div>{{faq.title}}<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-up': this.open, 'glyphicon-chevron-down': !this.open}"></i>
                    </div>
                </uib-accordion-heading>

                <div  ng-bind-html="faq.content"></div>
            </uib-accordion-group>
            </uib-accordion>

Here i provided the Plunker which i already posted in my Comment :- 在这里,我提供了已经在我的评论中发布的Plunker:-

plnkr.co/edit/iWEuuv?p=preview plnkr.co/edit/iWEuuv?p=预览

Just change is-open="this.open" to is-open="$first" and it will works. 只需将is-open="this.open"更改is-open="this.open" is-open="$first"

 angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap','ngSanitize']); angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) { $scope.oneAtATime = true; $scope.FAQs = [ { title: 'Overview', content: '<p>This Add-in reviews <b>External Users</b> for a Site Collection if number of days remaining to expire is <b>10 days</b>.Then generate and send <b>warning email</b> notifications to Site Collection Administrators/Person who sent external User Invite and Governance Team Memberrs.The warning email notification will contain following options :<ol><li> Extend Access</li><li> Remove User </li></ol></p><p>The same information regarding external users can be viewed through Site Actions Menu, Site Settings page and one time warning pop-up on site collection. This add-in also provisions an option in Site Actions Menu to display <b>Site Collection administrators</b>.</p>' }, { title: 'Who can use?', content: '<p>Users with only <b>admin</b> priviledges can view the external user details and edit their access time . However, <b>all</b> users can view the site administrator details. </p>' }, { title: 'How to Use?', content: '<p><ul><li>The add-in will be installed through <b>Spo.Provision</b> utility.</li><li>Right click on a row to perform \\'Extend Access\\' or \\'Remove User\\' operations from context menu.</li><li>In order to perform these opeartions for multiple users, select rows by holding <b>shift/Ctrl</b> keys and click on <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> for extending access and <span class="glyphicon glyphicon-minus" aria-hidden="true"></span> for removing selected users. </li><li><b> Please note</b> that you cannot extend access if user already has access for maximum limit.</li></ul></p>' }, { title: 'Settings & Configuration', content: '<p><ul><li>The configuration for timer job such as cut-off time and warning message can be done using App.Config file.</li></ul></p>' }, { title: 'Compatibility', content: '<p>Compatible with IE10 and upper version. Latest version of Chrome & Firefox.</p>' } ]; $scope.status = { isFirstOpen: true }; }); 
 <!doctype html> <html ng-app="ui.bootstrap.demo"> <head> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/angular-sanitize/1.5.0/angular-sanitize.min.js"></script> <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.14.3.js"></script> <script src="example.js"></script> <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div ng-controller="AccordionDemoCtrl"> <h1>OBJECT</h1> <uib-accordion close-others="oneAtATime"> <uib-accordion-group ng-repeat="faq in FAQs" is-open="$first"> <uib-accordion-heading> <div>{{faq.title}}<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-up': this.open, 'glyphicon-chevron-down': !this.open}"></i> </div> </uib-accordion-heading> <div ng-bind-html="faq.content"></div> </uib-accordion-group> </uib-accordion> </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM