0

I'm dealing with a huge dataSet using Angular5 service, so I want to call the backend API once and want to save the result into JSON.

I fetch the response and then store into several arrays according to my need,I'm looking how to add those arrays into JSON file.

getAllConcepts(){
   let allOrderUUID="b3dac224-fdea-11e4-b248-005056820298";
 this.allOrderableService.getAllOrderableConcepts(allOrderUUID).subscribe(allOrders=>{
    let allOrderable=allOrders;
    allOrderable.setMembers[0].setMembers.forEach(labSample=>{
      this.labSamples.push(labSample);
    });
    allOrderable.setMembers[1].setMembers.forEach(radOrder=>{
      this.radiologyOrder.push(radOrder);
    });
    this.separatePanelAndLabTestInlabSamples(this.labSamples);
    this.separatePanelAndOrderInRadiologyLab(this.radiologyOrder);    
  });
}

separatePanelAndLabTestInlabSamples(labSample:any){
  console.log("@receivedLabSample",labSample);
  if(labSample.length>0)
  {
    labSample[0].setMembers.forEach(response=>{
      if(response.conceptClass.uuid==="33a6291c-8a92-11e4-977f-0800271c1b75")
        {
          this.labSamplesTest.push(response);
        }
     if(response.conceptClass.uuid==="8d492026-c2cc-11de-8d13-0010c6dffd0f")
        {
          this.labSamplesPanel.push(response);
        }
  });
  console.log("LabTest",this.labSamplesTest);
  console.log("LabPanel",this.labSamplesPanel);
  }
}

I'm able to receive the response,after getting the reponse I'm storing them into severals arrays,I'm confuse how I can add these array into JSON file for future use.The basic aim is to reduce the call to server.

I want to add following arrays that exist in code into JSON File.

I have all the arrays, I need to convert them into JSON file.

R. Richards
  • 24,603
  • 10
  • 64
  • 64
  • That is not a client side dedicated functionality, even you can achieve it by workarounds, but still not recommended to write in files on the client side, else, If it is a `HUGE` response , why you do not just implement pagination in your server side ? – SeleM Dec 28 '18 at 14:26
  • this is just a utility which require once,Once I stored the result into json,I will deal with it.Are you sure it's not possible in angular? – Mohammad Naveed Dec 28 '18 at 14:32
  • I did not say it is not possible, you can achieve it in JS, but it is not recommended for security reasons. `Localstorage` wont help ? – SeleM Dec 28 '18 at 14:35
  • Will you please share a way,how I can acheive it in JS,security is not big concern for me. – Mohammad Naveed Dec 28 '18 at 14:39
  • And you'll continue using that file during application runtime or you just want response data to be stored in a file that'll be downloaded and that's all ? – SeleM Dec 28 '18 at 14:45
  • Possible duplicate of [How to create and save file to local fileSystem using AngularJS?](https://stackoverflow.com/questions/38462894/how-to-create-and-save-file-to-local-filesystem-using-angularjs) – Lex Lustor Dec 28 '18 at 15:16
  • I want to store it once,after that I want to use it during application where needed. – Mohammad Naveed Dec 29 '18 at 17:16

2 Answers2

0

As I know you can't save response to a file in angular, for that you need server-side access.

Ajantha Bandara
  • 1,473
  • 15
  • 36
0

You can look into PouchDB. It's a javascript version of CouchDB. It's noSQL based (with documents). So you could do then is to fetch the data, store them into the (local) pouchDB instance. Then from that point on, you just do calls to pouchdb.

fransyozef
  • 544
  • 2
  • 7
  • 18