Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable and disable a mat-button based on a select form

This is my mat-button:

<button class="example-20-width" mat-raised-button disabled>Edit Client</button> 

How can I control it and make it disabled or not based on whether a select form is emtry or not?

Here is my field form:

<mat-form-field class="example-full-width">   <mat-select  placeholder="Select customer">     <mat-option *ngFor="let food of books.data"          [value]="food.company">       {{food.company}}     </mat-option>     <mat-option>     </mat-option>   </mat-select> </mat-form-field> 
like image 992
Cap Barracudas Avatar asked Mar 02 '18 14:03

Cap Barracudas


People also ask

How do you use a toggle mat button?

By default, mat-button-toggle-group acts like a radio-button group- only one item can be selected. In this mode, the value of the mat-button-toggle-group will reflect the value of the selected button and ngModel is supported. Adding the multiple attribute allows multiple items to be selected (checkbox behavior).

What is Mat button?

mat-icon-button. Circular button with a transparent background, meant to contain an icon. mat-fab.


2 Answers

If you look at Angular Material Demos (button), which is an older version of Angular Material demo, there is a button performing this.

This demo used to correspond (it's now outdated) to the demo on the Angular GitHub page, see: github.com - Angular Material - src/demo-app/button.

You can simply use:

<button mat-button [disabled]="isDisabled"> 

where isDisabled is a boolean define in your component.

like image 60
moi_meme Avatar answered Oct 02 '22 21:10

moi_meme


use [disabled] atttribute with button

<button class="example-20-width"  [disabled]="true" mat-raised-button disabled>Edit Client</button> 
like image 41
Sajeetharan Avatar answered Oct 02 '22 21:10

Sajeetharan