Search Posts

Category: spring-jpa

I am trying to fetch details of patient from a url containing json data using get method of angular js2

My classes are: ****Patient Service class.ts**** @Injectable() export class PatientService{ url=”http://localhost:8080/rest/patientC”; constructor(private http:Http){} getPatientWithObservale():Observable<patient[]>{ return this.http.get(this.url) .map(this.extractdata) .catch(this.handleErrorObservable); } private extractdata(res:Response){ let body=res.json(); console.log(body.data); return body.data || {}; } } **Observable Component class.ts** export class ObservableComponent implements OnInit{ patients:patient[]; errorMessage: string; patientName: string; patient=new patient(); constructor(private patientService: PatientService){} ngOnInit(){ this.fetchPatient(); } fetchPatient():void{ this.patientService.getPatientWithObservale() .subscribe(patients=>this.patients = patients, error=>this.errorMessage=error); } } **Observable component.html** <h3>Patient Details with Observable </h3> <table> <tr> <th>Id</th> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Gender</th> […]