I have already installed ngx-pagination in one of my angular 5 project with laravel 5.5. My Angular project is consuming APIs from Laravel. I have included the following in the HTML, ts, and service files as follows:
// ts file
getPage(number){
this.productService.getURLpagengx(number).subscribe(data => {
this.products = data.products.data;
this.products_paging = data.products;
});
}
// service file
getURLpagengx(no): Observable<any>{
const url = '${this.url}/api/product?page='+no;
return this.http.get(url,{headers: new HttpHeaders({Authorization:'Bearer '+ this.token})});
}
<div class="row">
<article class="col-md-4" *ngFor="let product of products | paginate: { itemsPerPage: 1, currentPage: p, totalItems: products_paging.total }">
<div class="mt-3 mb-3">
<div class="col-md-12">
<div class="font-weight-bold">{{product.product_name}}</div>
<p>{{product.description}}</p>
<p>{{product.rating}}</p>
<div class="pt-2 pb-2 border-top border-bottom">
<div class="mt-1">
</div>
</div>
</div>
</div>
</article>
</div>
My Pagination is working well but the currently clicked button within the pagination is not activated/ active (e.g. blue).
Below is the jSON values which received from Laravel server side:
{
"products": {
"current_page": 2,
"data": [
{
"id": 6,
"product_name": "Patrick Stoltenberg",
"description": "Dinah, tell me the truth: did you call him Tortoise--' 'Why did they live on?' said Alice, who felt ready to ask help of any one; so, when the White Rabbit. She was looking up into the air off all.",
"rating": 8,
"price": 13.5,
"uploaded_image": "",
"created_at": "2018-03-22 05:34:39",
"updated_at": "2018-03-22 05:34:39"
},
{
"id": 7,
"product_name": "Micheal Davis",
"description": "Has lasted the rest of my own. I'm a deal faster than it does.' 'Which would NOT be an advantage,' said Alice, 'a great girl like you,' (she might well say this), 'to go on crying in this way! Stop.",
"rating": 3,
"price": 27.6,
"uploaded_image": "",
"created_at": "2018-03-22 05:34:39",
"updated_at": "2018-03-22 05:34:39"
},
{
"id": 9,
"product_name": "Minnie Ebert",
"description": "Mouse had changed his mind, and was going to leave off being arches to do it?' 'In my youth,' Father William replied to his son, 'I feared it might injure the brain; But, now that I'm perfectly sure.",
"rating": 0,
"price": 40.9,
"uploaded_image": "",
"created_at": "2018-03-22 05:34:39",
"updated_at": "2018-03-22 05:34:39"
},
{
"id": 10,
"product_name": "Noble Jerde1",
"description": "He looked at the top of its right ear and left off quarrelling with the bones and the beak-- Pray how did you do either!' And the executioner ran wildly up and beg for its dinner, and all the party.",
"rating": 14,
"price": 25,
"uploaded_image": "",
"created_at": "2018-03-22 05:34:39",
"updated_at": "2018-04-04 07:23:13"
},
{
"id": 11,
"product_name": "Flo Connelly",
"description": "INSIDE, you might do something better with the lobsters to the other, and making faces at him as he came, 'Oh! the Duchess, who seemed to her feet in a natural way again. 'I wonder if I've kept her.",
"rating": 9,
"price": 40.8,
"uploaded_image": "",
"created_at": "2018-03-22 05:34:39",
"updated_at": "2018-03-22 05:34:39"
}
],
"first_page_url": "http://localhost:8000/api/product?page=1",
"from": 6,
"last_page": 3,
"last_page_url": "http://localhost:8000/api/product?page=3",
"next_page_url": "http://localhost:8000/api/product?page=3",
"path": "http://localhost:8000/api/product",
"per_page": 5,
"prev_page_url": "http://localhost:8000/api/product?page=1",
"to": 10,
"total": 15
}
}