我如何在angular4的服务中调用管道?
我想在服务中呼叫一个管道 就像我如何在angular4的服务中调用管道?,angular,angular-pipe,Angular,Angular Pipe,我想在服务中呼叫一个管道 就像 export class MyService{ constructor(private http: Http){} getValues(){ this.http.get(baseUrl).pipe(//pipename) //I want to menton my custom pipe } } 管道完成后,我想将可观察的对象返回到组件。可能吗?是的,您可以像这样调用服务文件中的pipe- import { DatePipe } fro
export class MyService{
constructor(private http: Http){}
getValues(){
this.http.get(baseUrl).pipe(//pipename) //I want to menton my custom pipe
}
}
管道完成后,我想将可观察的对象返回到组件。可能吗?是的,您可以像这样调用服务文件中的
pipe
-
import { DatePipe } from '@angular/common';
class MyService {
constructor(private datePipe: DatePipe) {}
transformDate(date) {
this.datePipe.transform(myDate, 'yyyy-MM-dd');
}
}
由于您没有提供任何用例示例,我在示例中假设DatePipe
更新
请简要地写下您的问题,检查拼写,参见Stackoverflow文档。请遵循以下步骤:我想通过管道处理observable,比如
get(){this.http.get().pipe(//pipename)}
。是否可能?刚刚更新了问题。你知道这是可能的还是不可能的吗?你想在通过http
返回数据时使用管道吗?如果是这样,那么尝试在.map
中使用相同的选项。您可以修改您的答案吗?请检查更新的答案
export class MyService{
constructor(private http: Http, private yourPipe: YourPipe){}
getValues(){
this.http.get(baseUrl).map(res => {
return this.yourPipe.transform(res, ----whatever---);
});
}
}