Preview:
import { Injectable } from "@angular/core";
// we need these imports in order to do any http requests
import { Http, Response, Headers, RequestOptions } from "@angular/http";
import { Observable } from "rxjs/Rx";

@Injectable()
export class ArticleService {
  constructor(private http: Http) {}

  getArticles() {
    return this.http
      .get("http://localhost:8000/api/lessons")
      .map((res: Response) => res.json())
      .catch((error: any) =>
        Observable.throw(error.json().error || "Server Error")
      );
  }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter