angularjs - How to display data in angular accordion differently for each accordion -
i using angular accordion. display accordions based on object size in (ng-repeat). when click accordion heading should make api call , store result in variable (department details) , should displayed in expanded window of accordion.
when click first accordion, making api call , displaying data correctly in accordion window. but, when click second accordion making api call , data in both accordions (first , second) same because department details variable has result of second accordion api call.
how can display data unique each accordion?. should make api calls in controllers itself, store results in array, , use in html instead of making api calls when click accordion-heading. in advance.
html:
<accordion close-others="false"> <accordion-group is-open="isopen" ng-repeat="item in object"> <accordion-heading"> <span ng-click="ctrl.getinfo(item.id)"> {{item.label}} </span> </accordion-heading> <div> {{ctrl.departmentdetails}} </div> </accordion-group> </accordion>
controller:
public getinfo (departmentid): void { this.departmentdetails = null; this.services.getdepartmentdetails(departmentid).then((response):any=>{ this.departmentdetails= response; }); }
your problem ctrl.departmentdetails 1 string value use in each section of ng-repeat. current design updates value of 1 variable gets repeated many times. ctrl.departmentdetails has little ng-repeat , problem. right have same string bound many places in view , when getinfo(), updating 1 string, going update everywhere appears in html.
your getinfo(item) function should take item object , not id argument , set departmentdetails on on item object pass it. allow each item have own departmentdetails data.
you need make getinfo() add departmentdetails property item object when make api request, or else stick in array can use datasource view.
and change html this, or refers array of departmentdetails data collects user expands each section.
<accordion close-others="false"> <accordion-group is-open="isopen" ng-repeat="item in object"> <accordion-heading"> <span ng-click="ctrl.getinfo(item)"> {{item.label}} </span> </accordion-heading> <div> {{item.departmentdetails}} </div> </accordion-group>
Comments
Post a Comment