vittorio maiullari
vittorio maiullari

Reputation: 123

Subscribe to http observable on different event types Angular 2

I got a service which returns an observable from an http request with a json object.

  findContracts(json: any) {
    return this.httpService.POST(URL, json);
  }

In my component i subscribe to this service in the ngInit method so that on page load i get the data from the server.

 this.mySub = this.myService.findContracts(json).subscribe((data: any) => {
    // manage data
 });

But i need to call the same service with different parameters everytime i click some buttons (It is an html table which i can filter, order and update). How can i subscribe to all this kind of event using the same subscription?

Upvotes: 0

Views: 328

Answers (1)

Bogdan B
Bogdan B

Reputation: 934

Wrap it in a function, and call it every time you need. Also you probably don't need to assign that call to a variable.

Upvotes: 1

Related Questions