I have data coming via consuming Web API. I have two methods in component, load next and previous records. I want to load object data from iteration via click event and display it.
Component
export class NewResponseComponent implements OnInit {
private view: BehaviorSubject<ConsulationResponsesIdListDataModel>;
private responseCurrentState: ResponseCurrentStateDataModel;
private responses: ConsulationResponsesIdListDataModel;
private responseData = false;
constructor(private dataService: ConsultationResponsesListDataService,
private router: Router,
private session: SessionStorageService){}
ngOnInit(): void {
this.view = new BehaviorSubject<ConsulationResponsesIdListDataModel>(null);
this.loadData();
}
public loadData():void
{
this.dataService.getConsultationResponsesList(this.responseCurrentState.consultationId, this.responseCurrentState.responseTypeId, this.responseCurrentState.responsesRequestedStatus)
.subscribe(data =>{
this.view.next(data);
this.responses = data;
this.responseData = true;
});
}
public loadNextResponse():void
{
console.log("request for next response");
}
public loadPreviousResponse():void
{
console.log("request for previous response");
}
following template shows all data in response object but I want to bind with loadNextResponse() and loadPreviousResponse() method in above component
Template
<div *ngIf='responseData'>
<div *ngFor="let response of responses" class="form-row">
{{response.responseId}}
</div>
<button class="btn btn-default width-50 mb-xs" (click)="loadNextResponse()">Load Next Response</button>
<button class="btn btn-default width-50 mb-xs" (click)="loadPreviousResponse()">Load Previous Response</button>
I need to achieve something like this http://jsfiddle.net/h2G64/

this.loadData();fromngOnInit()and call it insideloadNextResponse()andloadPreviousResponse()