disable select in angular2
For your case it is enough to use markup [disabled]="butDisabled"
, but it is worth noting that this approach won't work for reactive forms, where you disable/enable controls in code:
this.form.get('myFormControlName').enable();
this.form.get('myFormControlName').disable();
You could just bind to the [disabled]
attribute like so:
<button type="button" class="btn btn-default" [disabled]="butDisabled">Disabled</button>
<select type="number" [(ngModel)]="levelNum" (ngModelChange)="toNumber()" [disabled]="butDisabled">
<option *ngFor="let level of levels" [ngValue]="level.num">{{level.name}}</option>
</select>
And in your component make the variable a boolean:
export class AppComponent {
butDisabled: boolean = true;
Working Plunker for example usage