gpt4 book ai didi

angularjs - 在 Angular ui Bootstrap 中控制 isOpen

转载 作者:行者123 更新时间:2023-12-04 19:02:33 25 4
gpt4 key购买 nike

我想在 angualr ui 引导 Accordion 指令中使用 isOpen 属性,这样它将打开 Accordion 中第一个 ng-repeat 的第一个元素。我尝试了一些没有运气的事情。有人可以就此提出建议吗?

    //html
<div ng-show="accordionCtrl.isNotString(value);" class="accordionContainer" ng-repeat="(key, value) in accordionCtrl.lessons">
<div class="accordionStepBox">
<h4 class="accordionStepTitle">Step {{$index+1}}: {{value.title}}</h4>
<span>Summary: {{value.summary}}</span>
</div>
<div class="accordionCoursesBox">
<div class="accordionCoursesText">Courses</div>

<!-- accordion for suffles -->
<uib-accordion close-others="accordionCtrl.oneAtATime">
<!-- only give accordion to object vals -->
<div class="accordion" ng-show="accordionCtrl.isNotString(value);" ng-repeat="(key, value) in value">
<!-- <uib-accordion-group heading="{{value.title}}" is-open="accordionCtrl.firstIndex($index)"> -->
<uib-accordion-group heading="{{value.title}}">
<div ng-repeat="(key, value) in value">
<div ng-show="accordionCtrl.isNotString(value);" class="accordionSuffleBox">
{{$index+1}}. {{value.title}}
</div>
</div>
<br/>
<button ui-sref="lesson" class="btn btn-default accordionbutton">Start</button>
</uib-accordion-group>
</div>
</uib-accordion>
</div>
</div>

//controller
angular
.module('neuralquestApp')
.controller('AccordionCtrl', AccordionCtrl);


function AccordionCtrl(FirebaseUrl, $firebaseObject, $firebaseArray) {
var accordionCtrl = this;
var getLessons = getLessons;

accordionCtrl.oneAtATime = true;

accordionCtrl.init = init;
accordionCtrl.init();
accordionCtrl.isNotString = isNotString;
accordionCtrl.firstIndex = firstIndex;

/*======================================
= IMPLEMENTATION =
======================================*/

function init() {
getLessons();
}

function firstIndex(index) {
if(index === 0){
return true;
} else {
return false;
}
}

function getLessons() {
var ref = new Firebase(FirebaseUrl);
accordionCtrl.lessons = $firebaseObject(ref.child('NeuralNetwork'));
}

function isNotString(val) {
// console.log('val', val);
if(typeof val === "string"){
console.log('is string', val);
return false;
} else {
return true;
}
}

}

最佳答案

is-open 属性设置为与 Controller 进行 2 路绑定(bind),因此您可以执行以下操作:

<div ng-controller="AccordionDemoCtrl">
<uib-accordion>
<div ng-repeat="group in groups">
<uib-accordion-group heading="{{group.title}}" is-open="openIndex[$index]">
{{group.content}}
</uib-accordion-group>
</div>
</uib-accordion>
</div>

angular.module('ui.bootstrap.demo').controller('AccordionDemoCtrl', function ($scope) {
$scope.openIndex = [true];

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

示例 plunk .此外,close-others 属性默认值为 true,因此您无需将其显式设置为 true。

关于angularjs - 在 Angular ui Bootstrap 中控制 isOpen,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34191116/

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