Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何在angular4的服务中调用管道?_Angular_Angular Pipe - Fatal编程技术网

我如何在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---);
    });
  }
}