I have a list getting data from firebase and it populates inside a form. I am able to get the handle of all the other fields of the form whereas not able to get the handle of the list selection. Setting formControlName to the ion-item throws error.
But, I am able to achieve the desired result through have the but not through the following one.
… in html file
<ion-header>
<ion-navbar colour="primary">
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>ExpenseForm</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list no-lines>
<form [formGroup]="expenseForm" (ngSubmit)="logForm()">
<ion-item>
<ion-label floating>Date</ion-label>
<ion-datetime displayFormat="MM/DD/YYYY" pickerFormat="DD-MM-YYYY" formControlName="expDate" ></ion-datetime>
</ion-item>
<ion-item>
<!-- <ion-list>
<ion-item *ngFor="let cat of cats | async" formControlName="scat">
{{cat.title}}
</ion-item>
</ion-list> -->
<ion-label floating>Select Category</ion-label>
<ion-select formControlName="scat">
<ion-option *ngFor="let cat of cats | async" >{{cat.title}}</ion-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label floating>Amount</ion-label>
<ion-input type="number" formControlName="amount"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Remark</ion-label>
<ion-input type="text" formControlName="remark"></ion-input>
</ion-item>
controller.ts
…@IonicPage()
@Component({
selector: ‘page-expense-form’,
templateUrl: ‘expense-form.html’,
})
export class ExpenseFormPage {
cats: FirebaseListObservable<any[]>; //get the list for items from firebase . have value
expenseForm: FormGroup;
constructor(public db: AngularFireDatabase, public navCtrl: NavController, public navParams: NavParams, public formBuilder: FormBuilder) {
this.cats = db.list(’/category’);
this.expenseForm = this.formBuilder.group({
expDate: ['', Validators.required],
amount: ['', Validators.required],
scat: ['' , Validators.required], -> this is the list to be populated from firebase.
remark: [''],
});
}