我想在angualr ui bootstrap accordion指令中使用isOpen属性,这样就可以打开手风琴中第一个ng-repeat的第一个元素.我尝试过一些没有运气的事情.任何人都可以就此提出建议吗?
//html//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; } } }Step {{$index+1}}: {{value.title}}
Summary: {{value.summary}}Courses {{$index+1}}. {{value.title}}
Rob J.. 5
is-open属性设置为与控制器进行双向绑定,因此您可以执行以下操作:
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' } ]; });{{group.content}}
示例plunk.此外,close-others属性的默认值为true,因此您无需将其显式设置为true.
is-open属性设置为与控制器进行双向绑定,因此您可以执行以下操作:
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' } ]; });{{group.content}}
示例plunk.此外,close-others属性的默认值为true,因此您无需将其显式设置为true.