I have a HTML page where i am displaying list of patient. (list called from service call to json server). when user clicks on a patient,it should display the details of the page.
in the services
getPatientList(): Observable<any> {
return this.http.get<any[]>(endpoint).pipe(
tap(data => console.log( JSON.stringify(data)))
);
}
getPatientDetails(id: number): Observable<any> {
return this.getPatientList().pipe(
map((patient: any[]) => patient.find(p => p.profile_no === id))
);
}
patient-details.ts
import { Component, OnInit, Input } from '@angular/core';
import { DataService } from '../services/data.service';
import { Router, ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-patient-details',
templateUrl: './patient-details.component.html',
styleUrls: ['./patient-details.component.css']
})
export class PatientDetailsComponent implements OnInit {
patient : any;
pId: number;
constructor(private data: DataService, private route: ActivatedRoute) { }
ngOnInit() {
this.data.getPatientDetails(this.pId).subscribe(
patient => this.patient = patient);
console.log(this.patient);
}
}
console.log(patient) display following in console.
Observable {_isScalar: false, source: Observable, operator: MapOperator}
here is the part of HTML template
<div class="form-group child">
<h1>{{patient.first_name}} {{patient.last_name}}</h1>
<div class="col form-group form-control-md mt-5">
<label for="profileNo" style="width:25%">Profile No: </label>
<label></label>
<input type="text" class="input-group-sm" [(ngModel)]="patient.profile_no">
</div>
<div class="col form-group form-control-md">
<label for="DOB" style="width:25%">Date of Birth: </label>
<input type="text" class="input-group-sm" [(ngModel)]="patient.DOB">
</div>
<div class="col form-group">
<label for="gender" style="width:25%">Gender: </label>
<input type="text" class="input-group-sm"[(ngModel)]="patient.gender">
</div>
<div class="col form-group">
<label for="bloodGroup" style="width:25%">Blood Group: </label>
<input type="text" class="input-group-sm" [(ngModel)]="patient.blood_group">
</div>