[Fixed]-How to display data from json retrieved from django-rest-framework?

1πŸ‘

βœ…

To consume any REST API you have to write a service like below,

 import { Injectable } from 'angular2/core';
 import { Http, Response } from 'angular2/http';
 import { Observable } from 'rxjs/Rx';

 export class Hero {
    id: number;
    name: string;
 }

 @Injectable()
 export class HeroService {
   constructor(private _http: Http) { }

   getHeroes() {
     return this._http.get('api/v1/heroes')
      .map((response: Response) => <Hero []>response.json())
   }
}

Hope this helps!!

πŸ‘€Madhu Ranjan

Leave a comment