Basically, I am trying to change/customize the behaviour of the ui.bootstrap.accordion. All is working, except for integration with ui-router.
Here's the way I want to use the accordion:
<accordion> <!-- this element is actually separate view in a parent state of the accordion-group's below.-->
<accordion-group ui-sref="site.home.newsID_1"> <!-- accordion-groups will be generated with ng-repeat.-->
<accordion-heading>
News 1
</accordion-heading>
<p>This is</p>
</accordion-group>
<accordion-group ui-sref="site.home.newsID_2">
<accordion-heading>
News 2
</accordion-heading>
<p>Home News's</p>
</accordion-group>
<accordion-group ui-sref="site.home.news.newsID_3">
<accordion-heading>
News 3
</accordion-heading>
<p>Preview and navigation</p>
</accordion-group>
</accordion>
Below's the modified template of the accordion:
<div ng-mouseenter="isOpen = !isOpen" ng-mouseleave="isOpen = !isOpen">
<div class="accordion-group" ng-class="{transparentBackground: isClicked}">
<div class="accordion-heading">
<a id="link" ui-sref="site" class="accordion-toggle" ng-click="isClicked = !isClicked" accordion-transclude="heading">
{{heading}}
</a>
</div>
<div class="accordion-body" collapse="!isOpen && !isClicked">
<div class="accordion-inner" ng-transclude></div> </div>
</div>
</div>
Basically the 'site.home.newsID_X' need to replace the 'site' value of ui-sref within the template.
My attempt was to set the value of ui-sref attribute via the 'element' parameter from the accordionGroup directive's linking function as shown below:
link: function(scope, element, attrs, accordionCtrl) {
element.find('#link').attr("ui-sref", attrs.uiSref)
[...]
}
This does update the target ui-sref, but ui-router does not generate the corresponding href from the referenced state's url, so after the DOM is rendered I am getting
<a ui-sref="site.home.newsID_1" href="#/site"></a>
instead of the expected
<a ui-sref="site.home.newsID_1" href="#/site/home/newsID_1"></a>
What am I missing?
I appreciate your time,
Jared