I have a next button that should be disabled if my observable value is false.
The observable is dataSource.next
(if there is more data - next is true, otherwise it's false). This disables the button and stops the user from navigating if there is no more data.
component.html:
<button mat-button (click)="next()" [disabled]="!dataSource.next$ | async">
<mat-icon>navigate_next</mat-icon>
</button>
However, although the value when outputted for dataSource.next is correct, it does not work as intended, perhaps it's because I'm trying to disable it if the value is false rather than true?
For example, when there is no more data, dataSource.next is false but the button is still enabled.
What is the solution?
The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).
Button component can be enabled/disabled by giving disabled property. To disable Button component, the disabled property can be set as true .
Put the async pipe in parenthesis.
<button mat-button (click)="next()" [disabled]="!(dataSource.next$ | async)">
<mat-icon>navigate_next</mat-icon>
</button>
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