angular - Set a default value to select -


i trying set default value ion-select option, on radio button "no" been clicked.

<ion-select class="brand" name="selectbrand" [(ngmodel)]="selectbrand" required>     <ion-option  *ngfor="let brand of brand;" [value]="brand.val">{{brand.name}}</ion-option> </ion-select>  <ion-col>     <ion-list radio-group name="checkbox" [(ngmodel)]="automanufacturers">          <ion-item>             <ion-label>yes</ion-label>                 <ion-radio  [value]="true"></ion-radio>         </ion-item>         <ion-item>             <ion-label>no</ion-label>             <ion-radio  (ionselect)="radiochecked()" [value]="false"></ion-radio>         </ion-item>     </ion-list> 

so when click on "no" in radio button need default array [1] place.

 brand = [         {             "name": "avin",             "val" : "avin"         },         {             "name": "amul",             "val" : "amul"         },         {             "name": "arokya",             "val" : "arokya"         },         {             "name": "thirumala",             "val" : "thirumala"         }];             radiochecked(){         console.log("hi");    selectbrand = this.brand[0]; } 

when try getting empty value, me

just @pierreduc says in comments, use property page hold selected value, can initialize default value.

component code:

@component({...}) export class yourpage {    public selectedbrandvalue: any;    // ...    constructor(...) {     // initialize select first value default     this.selectedbrandvalue = this.brand[0].val;   }    // ...  }  

view:

<ion-select class="brand" [(ngmodel)]="selectedbrandvalue" required>     <ion-option  *ngfor="let brand of brand;" [value]="brand.val">{{brand.name}}</ion-option> </ion-select> 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -