-1

I want to call a pipe with in a service.

just like

 export class MyService{

  constructor(private http: Http){}

  getValues(){
    this.http.get(baseUrl).pipe(//pipename) //I want to menton my custom pipe
  }
}

After completion of pipe I want to return that observables to component. Is it possible ?

1 Answers1

1

Yes, you can call pipe in service file like this-

import { DatePipe } from '@angular/common';
class MyService {

  constructor(private datePipe: DatePipe) {}

  transformDate(date) {
    this.datePipe.transform(myDate, 'yyyy-MM-dd');
  }
}

as you have not provided any example of your use case , I am assuming DatePipe here in my example.

Update

export class MyService{

  constructor(private http: Http, private yourPipe: YourPipe){}

  getValues(){
    this.http.get(baseUrl).map(res => {
       return this.yourPipe.transform(res, ----whatever---);
    });
  }
}
Community
  • 1
  • 1
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215