August 2017
Beginner to intermediate
370 pages
8h 37m
English
As discussed earlier, DoctorListComponent depends on DoctorService, which returns data asynchronously after making HTTP calls to the server. The following is the code for DoctorService. Pay attention to the getDoctorsBySpeciality and getDoctorsCount APIs, where the HTTP service invokes the get method:
import { Injectable } from '@angular/core';import { Http, Response } from '@angular/http';import { Observable } from 'rxjs/Observable';import 'rxjs/add/operator/catch';import 'rxjs/add/operator/map';import 'rxjs/add/observable/throw';import { Doctor } from './doctor';@Injectable()export class DoctorService { private doctorsUrl = 'http://localhost:8080/doctors'; public doctorsCount = 0; public doctors: Observable<Doctor[]>; ...
Read now
Unlock full access