Optimising *ngFor loops and *ngIf for large datasets (Angular 2) -


i'm displaying data json data (from api) using *ngfor , i'm bit concerned possible performance issues in approach. i'm looking suggestions on how improve it.

this json structure (without data) displaying in page: https://gist.github.com/fogofogo/f4b5ac9a765fc684e7e08b30221c6419

and json structure full data: https://gist.github.com/fogofogo/f7b5c3db347246689ea5007344eff53b

the json showing data 2 matches , @ 2k lines! potentially have 100 matches.

this using display data on page:

<div class="..." *ngfor="let sport of competition.sports">    <p>{{ sport.sport }}</p>    <ng-container *ngfor="let country of sport.countries">      <div class="..." *ngfor="let tournament of country.tournaments">        <p>{{ country.country }} - {{ tournament.tournament }}</p>        <div class="..." *ngfor="let fixture of tournament.fixtures" class="tournament_item">          <p>{{fixture.hometeam.name}} v {{fixture.awayteam.name}}</p>          <ng-container *ngfor="let market of fixture.markets">            <ng-container *ngif="market.marketid === 1">              <div class="..."  *ngfor="let marketoption of market.marketoptions">           {{ marketoption.fractionodds }}             </div>            </ng-container>          </ng-container>        </div>      </div>    </ng-container>  </div> 

and data controller this:

ngoninit() {  this.sub = this.route.params.subscribe(params => {    this.id = params['competitionid'];    this.service.get(this.id)   .subscribe(competition => this.competition = competition) }); } 

apart ridiculous amount of ngfors (which feels wrong), i'm particularly concerned *ngif="market.marketid === 1". need check on 20 markets in 100 matches. when run code in browser 250 matches takes 5 seconds load.

if offer advice on how optimise appreciate it. apologies glaring issues above - angular 2/4 new person here.

i recommend breaking simpler elements.

it looks you're building 1 element manage entire tree. if break bits, it'll easier build out larger structure.

so you'd have component shows single market option. options collection component ng-repeats collection of market options. tournament component...and on outwards.

it become large, if that's nature of data, it's nature of data.

once you've got structured, code filter data show needed should become obvious.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -