I would like to apply a click function:
setPage(page - 1)
But only if this condition matches:
page > 1
I thought I could do it like this but it didn't work, any ideas?
<a (click)="{'setPage(page - 1)' : page > 1}">Previous</a></li>
This should work:
<a (click)="page > 1 ? setPage(page - 1) : null">Previous</a></li>
similar example: http://plnkr.co/edit/ojO0GwQktneBuzKqKTwz?p=preview
As mentioned in the comments:
Create a new method in your component called for example onAnchorClick
and let it handle the logic.
public onAnchorClick(page: number) {
if(page > 1) {
this.setPage(page - 1);
// some other stuff to do
}
}
and bind it to your Anchor
<a (click)="onAnchorClick(page)">Previous</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With