-1
  1. I do have multiple pages, each page has different API calls. then do I need to create different resolvers for each page?
    1. can I implement resolve to the main service without adding new service?

I wrote resole service like this

resolve(route: ActivatedRouteSnapshot, rstate: RouterStateSnapshot): Observable <any>{

      return this.http.get(''+this.webAPI+'getproducts', {
        headers: {
          "Authorization": "Token " + this.token,
        },
        withCredentials: true
      }
      );
    }

inside my constructor is

this.actr.data.map(data => data.cres ).subscribe((response) =>{
      console.log("reas", response)
})
R. Richards
  • 24,603
  • 10
  • 64
  • 64
linto johny
  • 137
  • 1
  • 2
  • 9

1 Answers1

0

You would need to create a Service.

Please read up on the Angular tutorial.

https://angular.io/tutorial/toh-pt4

Create a service called "DataService". Then create some functions like

public getProducts(): Observable<any>{
    this.http.get(...)
}

Add this service to your Module's providers section.

Then "Import" your service into your Component constructor.

Now if you need to use this service again you won't have to "copy paste" the logic in all Components.

jriver27
  • 852
  • 5
  • 19
  • I have created the service. I am asking about the resolve method. I created the resolve service also. all working fine. but when I need to route using resolve method do i need to create different resolve files – linto johny Jun 29 '18 at 12:15
  • public getProducts(): Observable{ this.http.get(...) } if i do have multiple calls?? – linto johny Jun 29 '18 at 12:16
  • Maybe I misunderstood your reason for using a Resolver. What are you trying to accomplish? – jriver27 Jun 29 '18 at 12:23