Reputation: 2204
I am using select component 2 times for selecting the timings and i also added icon as a suffix to make action as add and cancel.As shown in below image
when i click the cancel icon then it is changing to add icon as shown in below image.
Here is the code
HTML
<mat-form-field class="no-line time">
<mat-select [(value)]="selectmonmor">
<mat-option *ngFor="let mondaymorning of mondaymornings" [value]="mondaymorning.value">
{{mondaymorning.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field class="no-line time">
<mat-select [(value)]="selectmoneve">
<mat-option *ngFor="let mondayevening of mondayevenings" [value]="mondayevening.value">
{{mondayevening.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
<button mat-button matSuffix mat-icon-button >
<mat-icon (click)="toggleIcon()">{{icon}}</mat-icon>
</button>
TS
public icon = 'highlight_off';
public toggleIcon() {
if (this.icon === 'highlight_off') {
this.icon = 'add_circle_outline';
} else {
this.icon = 'highlight_off';
}
}
Here on clicking the icon i,e <mat-icon (click)="toggleIcon()">{{icon}}</mat-icon>
the cancel icon(i,e highlight_off) it changing to add icon (i,e add_circle_outline) Now i need to disable the 2 dropdown(select components) on clicking the cancel icon then the icon will be changed to add, on clicking add select component as to be enabled.On surfing i got stackblitz link too
but here enable/disable actions are performing by 2 separate button using 2 click function, but i need it perform by only one icon.How can i do it?
Upvotes: 3
Views: 6314
Reputation: 7231
Try like this:
HTML:
<mat-toolbar color="primary">
Angular Material 2 App
</mat-toolbar>
<div class="basic-container">
<mat-form-field>
<mat-select placeholder="Sample" [disabled]="selectDisabled">
<mat-option *ngFor="let opt of [1, 2, 3, 4]" [value]="opt">
Option {{ opt }}
</mat-option>
</mat-select>
</mat-form-field>
<button (click)="selectDisabled = !selectDisabled" mat-icon-button>
<mat-icon >{{selectDisabled?'add': 'cancel'}}</mat-icon>
</button>
<pre>disabled: {{ selectDisabled }}</pre>
</div>
Upvotes: 1