Angular-Consuming HTTP service

Using the fake server

https://jsonplaceholder.typicode.com/

First of all, in order to use http, we need to import HttpModule inside @angular/http

import {HttpModule} from '@angular/http';
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';

@Component({
  selector: 'app-post',
  templateUrl: './post.component.html',
  styleUrls: ['./post.component.css']
})
export class PostComponent implements OnInit {

  constructor(http: Http) {
    http.get('https://jsonplaceholder.typicode.com/posts').subscribe(response =>{
      console.log(response);
    })
   }

  ngOnInit() {
  }

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *