Here is my StackBliz link https://stackblitz.com/edit/ionic-vdjegs
How to add “Each” values to ion-option from comma separated values
here is my ts file
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Validators, FormBuilder, FormGroup,FormControl } from '@angular/forms';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
questions:any;
private form : FormGroup;
constructor(public navCtrl: NavController,public formBuilder:FormBuilder) {
this.form = this.formBuilder.group({
});
this.questions=[
{id: "1",labels: null,name: "Grade of apple"},
{id: "2",labels: null,name: "Grade of orange"},
{id: "3",labels: "grade1,grade2, grade3,grade4",name: "Grade of grape"},
{id: "4",labels: "yes,no,sometimes",name: "Grade of grape"},
]
this.questions.forEach(que =>{
let control: FormControl = new FormControl('');
this.form.addControl(que.id, control);
});
}
logForm(){
console.log(this.form.value);
}
my HTML
> <ion-item *ngFor="let que of questions; let i=index">
> <ion-label floating>{{que.name}}</ion-label>
> <ion-input *ngIf="que.labels == null" type="text" [formControlName]="que.id"></ion-input>
> <ion-select *ngIf="que.labels != null" [formControlName]="que.id">
> <ion-option >{{que.labels}}</ion-option>
> </ion-select>
> </ion-item>
> <button ion-button type="submit">Save </button>
> </form>