简体   繁体   中英

How I can fetch data from get request using angular 2 pipe?

I tried more than one time to get data through api request using pipe. It return object object. Could you please help me to solve these problem.

import { Pipe, PipeTransform } from '@angular/core';
import { ApiService } from './api.service';

@Pipe({
  name: 'member'
})

export class MemberNamePipe implements PipeTransform {

  constructor(public apiService: ApiService) {}

  transform(value: any): any {
    if(value == undefined) return value; 
      return this.apiService.getMemberName(value).subscribe(
        data => {return data.data},
        err => {console.log(err)}
     )
  }
}

You might want to take a look at AyncPipe https://angular.io/docs/ts/latest/api/common/index/AsyncPipe-pipe.html

If you still want to use normal pipe then you should pre-load the data from server and use it inside your pipe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM