Currently, I am working on a project in Angular2 that requires the use of an online JSON file. I have utilized http.get
to retrieve the file, but I only need the data from the second and third columns which contain the first name and last name.
If you want to view the JSON file, here is the link >
Below, you can find the code snippets I am using:
admin1.component.ts - where the dates are displayed
import { Component } from '@angular/core';
import { UserService } from '../services/user.service';
@Component({
moduleId: module.id,
selector: 'admin1',
templateUrl: `admin1.component.html`,
})
export class Admin1Component {
enable: boolean;
_profile: {}
constructor(private userService: UserService) {
this.enable = false;
}
loadUser() {
this.userService.getUser().subscribe(data => this._profile = data);
this.enable = true;
}
}
my user.service.ts
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class UserService {
constructor (private http: Http) {}
getUser() {
return this.http.get('http://alexgr.ro/ehealth/patients.json')
.map((res:Response) => res.json());
}
}
and my admin1.component.html
<div>
<button (click)="loadUser()">Load User</button>
<div *ngIf="enable">
{{ _profile | json }}
</div>
I would greatly appreciate any assistance with this issue