Dartfrog Imi Dartfrog Imi - 1 month ago 32
TypeScript Question

How to disable ion-select using typescript. ionic 2

I can disable ion-select using disable attribute like the following:

<ion-item>
<ion-label stacked>Property Type</ion-label>
<ion-select [(ngModel)]="propType" (ionChange)="ionChanger()" disabled="true" >
<ion-option value="{{ptype}}" *ngFor="let ptype of PropTypeArray">{{ptype}}</ion-option>
</ion-select>
</ion-item>


How can i disable from typescript file? I tried the following command but no luck

In my type script file

disableSelector:boolean

constructor(){
this.disableSelector = true;
}


here is in the html file

disabled = "disableSelector"


totally cannot work at all

best Rgds,
frog

Answer

You are using disableSelector variable so you need to use it with [disabled] property binding as shown below,

<ion-item>       
      <ion-label stacked>Property Type</ion-label>
          <ion-select [(ngModel)]="propType" 
                      (ionChange)="ionChanger()" 

                      [disabled]="disableSelector" >  //<<< This is required.

           <ion-option value="ptype"                  //<<< removed {{}} braces.
                      *ngFor="let ptype of PropTypeArray">
                             {{ptype}}
          </ion-option>    
       ...             
 </ion-item>