javascript - ng-repeat causing delay in Ionic app (Angular) -
in controller, have object (sorted_users
) containing name , linkedin id of people, sorted alphabetically:
{ "a":[ {"name":"an something","linkedinid":"..."}, {"name":"arthur somethingelse","linkedinid":"..."}, {"name":"ashton lastname","linkedinid":"..."}], "b":[ {"name":"ben blabla","linkedinid":"..."}, {"name":"bianca someone","linkedinid":"..."}, {"name":"borris random","linkedinid":"..."}, ... , on
my html:
<div ng-repeat="(letter, names) in sorted_users" class="alpha_list"> <ion-item class="item item-divider" id="index_{{letter}}"> {{letter}} </ion-item> <ion-item class="item-icon-right" ng-repeat="n in names | filter :{name:search}"> <h2>{{n.name}} <i class="icon ion-social-linkedin" ng-if="n.linkedinid" ng-click="openlinkedin(n.linkedinid)"></i></h2> </ion-item> </div>
while works, i'm getting performance issues when there +400 people. clicking on link links page people should be, results in pause of 3-4 seconds. after that, animation kicks in , app navigates people page.
i used show people without alphabet divider. array looked this:
[ {"name":"an something","linkedinid":"..."}, {"name":"arthur somethingelse","linkedinid":"..."}, {"name":"ashton lastname","linkedinid":"..."}, {"name":"ben blabla","linkedinid":"..."}, {"name":"bianca someone","linkedinid":"..."}, {"name":"borris random","linkedinid":"..."}, ... , on
and in html, use collection-repeat:
<ion-item class="item-icon-right" collection-repeat="n in unsorted | filter :{name:search}"> <h2>{{n.name}} <i class="icon ion-social-linkedin" ng-if="n.linkedinid" ng-click="openlinkedin(n.linkedinid)"></i></h2> </ion-item>
this removes performance issues, doesn't allow me put alphabetical dividers.
i see 2 solutions satisfy needs:
possible solution 1:
using collection-repeat sorted_users
. i'm unable work: collection-repeat expected array 'sorted_users', got undefined
possible solution 2:
showing loading spinner when clicking button, , after delay, remove again navigate page. i've tried adding controller:
$scope.gotopeople = function() { $ionicloading.show({ content: 'processing...', template: "<ion-spinner></ion-spinner><br />processing...", showbackdrop: true, showdelay: 0 }); $timeout(function () { window.location="...link people page..."; }, 100); };
and then:
$scope.$on('$ionicview.beforeleave', function(){ $ionicloading.hide(); });
this seems work, during delay, spinner freezes , stops "spinning". it's there, looks app crashes (which isn't case).
you can try load list in several times thanks-to
<ion-infinite-scroll ng-if="moredatacanbeloaded()" on-infinite="loadmore()" distance="1%"> </ion-infinite-scroll>
Comments
Post a Comment