I have a built an angular 2 app to fetch data from oracle db, and displaying it in the view, whenever i switch between the routes, everytime the view is loading to get data from DB. How can i make it fetches data only once until i click some control to fetch data.
Service:
getTaskDetails(taskId : Number): Promise<String[]> {
this.heroesUrl='http://localhost:3007/getTaskDetails';
return this.http.get(this.heroesUrl+"?taskId="+taskId)
.toPromise()
.then(function(response){
console.log("Test"+response.json());
return response.json();
})
.catch(this.handleError);
}
Component:
getHeroes(agentID : Number,filterDateFrom : String,filterDateTo : String): void {
this.heroService
.getTaskByDate(taskId)
.then((dataGSD)=>
this.dataGdsp = dataGSD
);
View:
<table *ngIf="dataGdsp" id="customers">
<tr>
<th>AGENT_ID</th>
<th>TASK_ID</th>
<th>PARENT_PROCESS_NAME</th>
<th>INITIATION_POINT_NAME</th>
</tr>
<tr *ngFor="let d of dataGdsp; let i = index">
<td>{{d.AGENT_ID }}</td>
<td>{{d.BPM_INSTANCE_ID}}</td>
<td>{{d.PARENT_PROCESS_NAME}}</td>
<td>{{d.INITIATION_POINT_NAME}}</td>
</tr>
</table>