Call doesnt work due to upgrades in RXjs version 6 is incorporated in angular version8. for complete source code see:- https://github.com/ankit01122/CRUDApp
import { Component } from '@angular/core';
import {ServicexampleService} from './servicexample.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'CRUDApp';
heroes: object;
constructor(private serviceExample: ServicexampleService) {
this.heroes = serviceExample.returnABC();
}
getHeroes(): void {
this.heroes = this.serviceExample.returnABC();
}
}
import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ServicexampleService {
private httpClient: HttpClient;
private abc: Observable<object>;
constructor( httpClient: HttpClient ) {
this.abc = httpClient.get('https://jsonplaceholder.typicode.com/todos/1');
}
public returnABC = (): Observable<object> => this.abc;
}
Service should get executed and get data on http://localhost:4200/