Answer the question
In order to leave comments, you need to log in
Angular - do you need routing, or should the scheme be different?
Good afternoon!
There is a one-page application - a feed of news. There is a "Show more" button. Initially, I draw 5 news items per page when loaded with $http.get(/feed). The question is, how to organize additional loading of data, given that backs give the next page something like /feed/2?
I read about routes, but they won’t help me along the way, I just need to get a model, views are not needed.
As I see it, when you click on the button, you need to call a service that passes the ID of the next / previous page to the controller, and the controller accordingly receives the model via $http and draws the view.
The question is how to organize this using angular?
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
it all depends on the requirements. The easiest option is to create a service and a method that will take a "page number" and return a list of models, store the current page in a variable. The call code will look something like this
this.modelCollection = [];
this.page = 0;
this.loadMore = function(){
this.page++;
this.feedService.get(this.page).then(function(data){
//тут склеиваем данные в modelCollection
});
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question