javascript - Managing scope in nested UI Bootstrap accordions -
i using ui-bootstrap simple accordion menu. tried nest them, can't scope of nested element.
ng-click won't work, guess because it's used open , close accordion. there way parent element child?
html:
<div ng-controller="accctrl"> <accordion close-others="oneatatime"> <accordion-group heading="classic accoridion (1)" is-open="$parent.step1"> <a href="" ng-click="clasclick()">classic click</a> </accordion-group> <accordion-group heading="nested accordian (2)" is-open="$parent.step2"> <accordion close-others="oneatatime"> <accordion-group heading="test (3)" is-open="$parent.step3"> <a href="" ng-click="nestclick()">nested click</a> </accordion-group> </accordion> </accordion-group> </accordion> <p> step1: {{step1}} <br/>step2: {{step2}} <br/>step3: {{step3}} <br/> <a href="" ng-click="opentwo()">open two</a> <br/> <a href="" ng-click="openthree()">open three</a> </p> js:
function accctrl($scope, $http, $timeout) { $scope.oneatatime = true; $scope.step1 = true; $scope.step2 = false; $scope.step3 = false; $scope.opentwo = function() { $scope.step2 = true; } $scope.openthree = function() { $scope.step3 = true; } $scope.clasclick = function() { console.log("classic clicked"); } $scope.nestclick = function() { console.log("nested clicked"); } }
it looks every accordion directive creating own scope. more details have implementation of accordion @ https://github.com/angular-ui/bootstrap/blob/master/src/accordion/accordion.js
to access parent of parent can type $parent.$parent this:
<accordion close-others="oneatatime"> <accordion-group heading="classic accoridion (1)" is-open="$parent.step1"> <a href="" ng-click="clasclick()">classic click</a> </accordion-group> <accordion-group heading="nested accordian (2)" is-open="$parent.step2"> <accordion close-others="oneatatime"> <accordion-group heading="test (3)" is-open="$parent.$parent.$parent.step3"> <a href="" ng-click="$parent.$parent.$parent.nestclick()">nested click</a> </accordion-group> </accordion> </accordion-group> </accordion>
Comments
Post a Comment