Skip to content

Commit

Permalink
On a home component add code to query and display results from any API
Browse files Browse the repository at this point in the history
  • Loading branch information
mac2000 committed Dec 28, 2020
1 parent 4b019e1 commit ba7d369
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
export class AppComponent implements OnInit {
title = 'ai704';

constructor(private http: HttpClient) {}

ngOnInit() {
this.http.get('https://jsonplaceholder.typicode.com/todos/1').subscribe(todo => this.title = todo['title'])
}
}
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -10,7 +11,8 @@ import { AppComponent } from './app.component';
],
imports: [
BrowserModule,
AppRoutingModule
AppRoutingModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down

0 comments on commit ba7d369

Please sign in to comment.