简体   繁体   中英

Slow performance when rendering and filtering long list in Angular

I've been developing an angular application and have a fairly long list (1600+ rows). When downloading the list, my application freezes and takes a really long time (+/- 10 seconds) to display the data. I don't think this is right and have found some solutions on the internet. These tips however don't seem to affect the loading time.

While loading I had a look at the dev-tools in Google Chrome, which gave me this strange result:

慢速加载角度

You can see that after loading the application freezes and takes more than 5 seconds to recover.

the function I call here is the following:

function loadInschrijvingen(activiteit_id, module_id, periode_id, groep_id){
    inschrijvingService.getInschrijvingenById(activiteit_id, module_id, periode_id, groep_id).then(function(response){
        applyInschrijvingen(response);
    });
}

the corresponding service function:

function getInschrijvingenById(activiteit_id, module_id, periode_id, groep_id){
    var request = $http({
    url: API_URL + 'inschrijvingen',
    method: 'GET',
    params: {activiteit_id: activiteit_id, module_id: module_id, periode_id: periode_id, groep_id: groep_id}
        });
   return (request.then(handleSuccess, handleError));
}

the url is just a normal DB query to fetch the rows. Also filtering is a mess. It takes 5 seconds to search the rows, while only filtering the last name.

<input type="text" placeholder="zoeken op achternaam" ng-model="inschrijving.achternaam" ng-model-options="{debounce: 500}">


<tr class="fold new" ng-repeat="inschrijving in inschrijvingen | filter: inschrijving  track by inschrijving.id">
    <td>@{{$index+1}}</td>
    <td><span ng-click="toggle('edit', inschrijving.id)"></span></td>
    <td><span ng-click="confirmMail(inschrijving.id)" title="Inschrijvingsmail herzenden"></span></td>
    <td><span ng-click="confirmReminder(inschrijving.id)" title="Betalingsherinnering verzenden"></span></td>
    <td><span ng-click="confirmDelete(inschrijving.id)"></span></td>
    <td>@{{inschrijving.voornaam}} @{{inschrijving.achternaam}}</td>
    <td><a href="mailto:@{{inschrijving.email}}">@{{inschrijving.email}}</a></td>
    <td>@{{inschrijving.geboortedatum | date:'dd/MM/yyyy'}}</td>
    <td><i class="fa" ng-class="{'fa-male': inschrijving.geslacht == 'man', 'fa-female': inschrijving.geslacht == 'vrouw'}"></i></td>
    <td>@{{inschrijving.straat}}, @{{inschrijving.postcode}} @{{inschrijving.gemeente}} </td>
    <td>@{{inschrijving.gsm}}</td>
    <td><input type="checkbox" ng-model="inschrijving.betaald" ng-true-value="1" ng-false-value="0" ng-checked="inschrijving.betaald == 1" ng-change="setState(inschrijving.id, 'postBetaald')"></td>
    <td>
    <select name="betalingswijze" id="betalingswijze" ng-model="inschrijving.betalingswijze" ng-change="setState(inschrijving.id, 'postBetalingswijze')">
        <option value="0" ng-selected="inschrijving.betalingswijze == 0">Geen</option>
        <option value="1" ng-selected="inschrijving.betalingswijze == 1">Cash</option>
        <option value="2" ng-selected="inschrijving.betalingswijze == 2">Overschrijving</option>
    </select>
    </td>
    <td><input class="bedrag" type="text" value="@{{inschrijving.bedrag}}" ng-model="inschrijving.bedrag" ng-change="setState(inschrijving.id, 'postBedrag')" ng-model-options='{ debounce: 1000 }'></td>
    <td><input type="checkbox" ng-model="inschrijving.fotos" ng-true-value="1" ng-false-value="0" ng-checked="inschrijving.fotos == 1" ng-change="setState(inschrijving.id, 'postFotos')"></td>
    <td>
    <select name="tshirtmaat" id="tshirtmaat" ng-model="inschrijving.tshirtmaat" ng-change="setState(inschrijving.id, 'postTshirtmaat')" >
        <option value="" ng-selected="inschrijving.tshirtmaat == ''"></option>
        <option value="92" ng-selected="inschrijving.tshirtmaat == 92">92</option>      
        <option value="L" ng-selected="inschrijving.tshirtmaat == 'L'">L</option>
    </select>
    </td>
    <td>@{{inschrijving.opmerkingen}}</td>
</tr>

I'm really stuck with this, so if anyone could help me out?

I would suggest breaking down your application part by part, until you find the culprit.

  • My first thing to try would be to remove the filter completely and see how that affects the load times/freezing

  • Try removing any other requests on the page (eg the fonts you are loading etc) to rule out any external factors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM