Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Accordion doesn't propagate is-open to parent scope #1034

Closed
laz2 opened this issue Sep 18, 2013 · 6 comments
Closed

Accordion doesn't propagate is-open to parent scope #1034

laz2 opened this issue Sep 18, 2013 · 6 comments

Comments

@laz2
Copy link

laz2 commented Sep 18, 2013

accordion.js, line 94

scope.$watch('isOpen', function(value) {
    if ( value ) {
        accordionCtrl.closeOthers(scope);
    }
    if ( setIsOpen ) {
        setIsOpen(scope.$parent, value); // <---
    }
});

This code sets isOpen in parent scope, but for 'accordionGroup' directive parent scope is scope of 'accordion' directive. IMHO, just replace scope.$parent with scope.$parent.$parent

@pkozlowski-opensource
Copy link
Member

@laz2 http://plnkr.co/ with a reproduce scenario, please...

@bekos
Copy link
Contributor

bekos commented Sep 19, 2013

@laz2 is right! Actually there are cases (our demo page is one of them) that user's scope is 3 $parent up.
I think the only safe way to access the appropriate scope is through accordion.

Will submit PR soon.

bekos added a commit to bekos/bootstrap that referenced this issue Sep 19, 2013
@bekos bekos closed this as completed in 157f614 Sep 19, 2013
@kirkhoff
Copy link

@bekos I'm noticing that after this change I'm no longer able to set isOpen to a scoped variable in a parent controller of the accordion. Example: If I want to set your variable, "isopen" to true by default in my controller, $watch won't pick it up anymore. Thoughts?

@bekos
Copy link
Contributor

bekos commented Dec 18, 2013

@kirkhoff This commit was buggy :-( It has been corrected by 9ec2128. Can you try with latest build from master? If not working, you can open a new issue with a plnkr to reproduce.

@kirkhoff
Copy link

@bekos too funny. That's exactly what I ended up doing on my end. Thanks for the fast response :)

@cottrelld
Copy link

Ran into this on the latest. I have a controller with variables such as isOpen1 isOpen2, etc. One for each accordionGroup.

isopen1={{isopen1}}

   <accordion close-others="false" class="ui-accordion" id="myAcc">
        <accordion-group is-open="$parent.isopen1"  id="category-1">
            <accordion-heading>
                My Heading here <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isopen1, 'glyphicon-chevron-right': !isopen1}"></i>
            </accordion-heading>

... bunch of controls then

Next Section    

doset is a method on my controller:

    $scope.doset = function() {
        $scope.isopen1=false;
        $scope.isopen2=true;
    }

Changing the variables this way has no effect with the master code. Setting setIsOpen(scope.$parent, value); as suggested above makes the code work and the accordions close/open as expected for me...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants