How to handle a large json without re-loading it for each page?


#1

Hi,

I am creating an app that search through a large json (250 000 rows), stored locally. Each page is pretty much the same on each page. I made a service, and import the json file in every page. I always need the full json file. However it takes couple of seconds to charge a page. How to avoid it and charge it only once when the app is launching?

(Am I clear?)

My service:

import {HTTP_PROVIDERS} from 'angular2/http';
import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import 'rxjs/Rx';


@Injectable()
export class Page1Service {   
    
     public dataDic : any;
    
    public constructor(private _http: Http) {
        this.dictionary();
    }
    
    
  
  public dictionary(){
 
this._http.get('theJsonFile.txt')
  .map((response: Response) => response.json())
  .subscribe(data=>{
    this.dataDic=data;
    console.log("I am loaded");
  });

    
}
}

How I Import i on eachpage:

public constructor(private _DicoctionaryService: Page1Service) {

   
  }

And then I access “dataDic” to do what I need to do. Should I bootstrap the json?

Thanks,

Stéphane.


#2

Hum. I think the answer is “global variables”.