I have a service which provides me an observable through a http get request and a following map operation. In my component I subscribe to the observable in the ngOnInit method. As I have a pagination functionality I would like to fire another request to the service when the user clicks on another page of the paginator. How can I achieve this? Do I have to subscribe to the service in a new method again or is it possible to initialize an observable within the component so I can use it in any method?
export class ListItemsComponent implements OnInit {
private _listItems = [];
page = 1;
constructor(private _listItemsService:ListItemsServiceService) { }
ngOnInit() {
this._listItemsService.getListItems (this.page)
.subscribe(listItems => this._listItems = listItems);
}
pageChange(page){
this._listItemsService.getListItems (this.page)
.subscribe(listItems => this._listItems = listItems);
}
}