1

here I need a suggestion or better approach related to multi URL consumption scenario: I have a JSON file in assets folder where it contains multiple URLs like below

{
    "Url1": "http://dummy.restapiexample.com/",
    "Url2": "https://reqres.com"
     "url3": "https://fakeapi.com"
}

with using environment.ts or without environment.ts I need to consume these URLs and

how I trying to consume is

consuming a json file to --> config.service.ts -->Setting.service.ts(where each url will have differnt methods basing on url it will call that method) --> dataLayer.service.ts --> some.component.ts

JSON --> config.service.ts (where it loads the json file) config.service.ts --> settings.service.ts (where it choose which url to be called )

 ex: 
      public x(){
       return  url1
    }

    public y(){
       return url2 
    }

like above based on a call from dataLayer.service.ts it calls some diff methods
in settings.service.ts --> dataLayer.service.ts

here it calls settings methods like

  public Method1(){
   this.settings.x()
 }

and this data layer is called using some.compoent.ts

this.datalayer.method1.susbscribe(res => {res})

so my point is how can I implement injection token scenario or APP_INITIALIZER

Anusha_Mamidala
  • 397
  • 2
  • 11
Jibin
  • 11
  • 4
  • see this tutorial: https://www.intertech.com/Blog/angular-4-tutorial-run-code-during-app-initialization/ – alt255 Mar 24 '19 at 11:46
  • this link may help you https://stackoverflow.com/questions/55285323/how-to-import-json-config-to-environment-ts-and-consume-api-using-angular/55285461 – Hien Nguyen Mar 24 '19 at 13:55
  • @HienNguyen exactly thank you i will take a look – Jibin Mar 24 '19 at 15:57

0 Answers0