0

I am trying to figure out how to close an accordion group from a button within the group.. seems like it should be easy.. but looks to be something with the scope being defined only within the group and not available in the controller? in the code snippet below the first button is how I would like to close the accordion group. The second button works.

Here is a simple plunkr on what I'm working on https://plnkr.co/edit/bghRaioszH3SZmiWxcoH?p=preview

 <uib-accordion close-others="true" ng-controller="testCtrl">
      <uib-accordion-group panel-class="panel-primary" is-open="status.isOpen">
        <uib-accordion-heading>
        Open: {{ status.isOpen }}
        <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.isOpen, 'glyphicon-chevron-right': !status.isOpen}"></i>
        </uib-accordion-heading>
      <button class="btn btn-warning" ng-click="close()">Cancel</button>
      <button class="btn btn-warning" ng-click="status.isOpen=!status.isOpen">Cancel</button>
  </uib-accordion-group>
    </uib-accordion>

1 Answer 1

1

To access the status of an accordion group through your controller's scope, you need to do something like this:

  1. Move ng-controller="testCtrl" to the <body> element

  2. Define status explicitly in your controller's scope:

.controller('testCtrl', function($scope) { $scope.status = { isOpen: true } $scope.close = function(){ $scope.status.isOpen = false; }; });

Sign up to request clarification or add additional context in comments.

3 Comments

in my production application the controller is defined in the view state definition.. Dozens of other functions of the controller are working fine.
hmm! making that change in the plunkr does indeed create the outcome im looking for! i guess i need to figure out how to incorporate using the .state router controller model i am using.
well. Not sure what i changed to make it work. The above answer must have lead me there somehow. everything is working now.. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.