From f0a375290f3beae3df09dc9ff675377960bdf410 Mon Sep 17 00:00:00 2001 From: Matt Huntington Date: Sat, 17 Jun 2017 21:38:45 -0400 Subject: [PATCH] making request to swapi and logging response --- src/app/app.module.ts | 5 ++++- src/app/films/films.component.ts | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e389284..307c426 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -4,13 +4,16 @@ import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { FilmsComponent } from './films/films.component'; +import { HttpModule } from '@angular/http'; + @NgModule({ declarations: [ AppComponent, FilmsComponent ], imports: [ - BrowserModule + BrowserModule, + HttpModule ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/films/films.component.ts b/src/app/films/films.component.ts index 12272bf..530346e 100644 --- a/src/app/films/films.component.ts +++ b/src/app/films/films.component.ts @@ -1,4 +1,7 @@ import { Component, OnInit } from '@angular/core'; +import { Http } from '@angular/http'; + +import 'rxjs/add/operator/toPromise'; @Component({ selector: 'app-films', @@ -7,9 +10,12 @@ import { Component, OnInit } from '@angular/core'; }) export class FilmsComponent implements OnInit { - constructor() { } + constructor(private http: Http) { } ngOnInit() { + this.http.get('http://swapi.co/api/films/') + .toPromise() + .then(response => console.log(response.json().results)); } }