I'm a newbie in Angular. What i'm doing is loading data from json file on click, which so far i have done correctly.
But the point where im stuck is to load the first json object before click, i.e to load the first object when the page loads
Typescript
export class RequestComponent{
people: Object[];
constructor(http:Http){
http.get('data.json').subscribe(res => {
this.people = res.json();
});
}
public currentStatus;
public setThis = (people) => this.currentStatus = people;
}
Html
<ul class="col-md-4">
<li *ngFor="let person of people" (click)="setThis(person)">
<span><i class="fa fa-cog" aria-hidden="true"></i></span>
<p>{{ person.name }}</p>
</li>
</ul>
<div *ngIf="currentStatus" class="col-md-8 right-section">
<h2>{{ currentStatus.name }}</h2>
<img [src]="currentStatus.img" class="img-responsive"/>
</div>