Angular 4 proper way to cast http response

后端 未结 3 1207
自闭症患者
自闭症患者 2021-01-17 05:03

I\'ve created a service in Angular 4 and I\'m fetching data via REST/JSON (new to Angular) using this code:

Interface

export interface IItem {
    Id         


        
3条回答
  •  半阙折子戏
    2021-01-17 05:39

    Youll want to use the map operator:

    @Injectable()
    export class ItemTest {
    
        constructor(private _http: HttpClient) {}
    
        getItems(): Observable {
            return this._http.get('url').map((data) => data['d']['results'])              
                .do(data => {
                    console.log(data);
                })
        }
    }
    

提交回复
热议问题