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

Losing template scope in component ( Accordion . toggleOpen() ) #2291

Closed
kosz opened this issue Jun 3, 2014 · 3 comments
Closed

Losing template scope in component ( Accordion . toggleOpen() ) #2291

kosz opened this issue Jun 3, 2014 · 3 comments

Comments

@kosz
Copy link

kosz commented Jun 3, 2014

I am having trouble accessing template methods from within my code.

I have the need to customize accordion header, to include a set of buttons :

https://gist.github.com/kosz/7fc8532bed9e68753ff2#file-accordion_buttons-jade

As you can see, in this file, i'm trying to ng-click="toggleOpen()" on a button that will handle expanding and colapsing. This would allow me to have other buttons and attach other events on the accordion header. I've had this working fine with my own code, but trying to standardize and use angular-ui bootstrap.

I have implemented this template :

https://gist.github.com/kosz/7fc8532bed9e68753ff2#file-index-jade-snippet

and it works fine, except for the fact that toggleOpen() is not available here . if i add toggleOpen() inside the template, it works just fine, but of course, it prevents me from calling any other methods on click from it's children.

Am i missing something here ?

@kosz
Copy link
Author

kosz commented Jun 3, 2014

I think i've tried anything I could to get this working.

Today I tried setting $scope.isOpen = true from a custom method within my controller. Still no reaction from the Accordion. The only way I can get it open is by having toggleOpen() bound with ng-click inside the template, but that takes away my ability to have my own buttons with their own ng-clicks inside the {{heading}} .

The only other option I can think of, is to add something like {{heading}} {{buttons}} to the template, then have {{buttons}} render my buttons ... But I feel like that would be hacking the component, and atm i am not even sure how to achieve this.

Bottom line is that it would be ideal if I could access the component scope from within my controller/views so that I can trigger the open event from wherever I want.

I've also looked at how this is done in the demo with the button that calls ng-click="status.open = !status.open" but i fail to understand how this works in the demo. I have not been able to get it working in my code. I've had this behaviour setup and working before, but things stopped working once i took toggleOpen() out of the template

@rvanbaalen
Copy link
Contributor

Can you please re-test in Angular 1.3 and UI Bootstrap 0.13? Also, provide a link to a plunkr reproducing your problem.

@wesleycho wesleycho added this to the Purgatory milestone Aug 2, 2015
@wesleycho
Copy link
Contributor

One has access to the is-open attribute, which allows one to programmatically toggle opening and closing of the accordion, as can be seen here.

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

3 participants