问题描述:

When looping over the the scope variable extra I am getting the id using item.id. Now I want to append the item.id with BookingConfirmationFormsState so it becomes e.g. BookingConfirmationFormsState35

When I run the following code I get an error

ORIGINAL EXCEPTION: Cannot read property '35' of undefined

The following is what I am currently working with.

HTML

<form (ngSubmit)="ContinueBookingConfirmation()">

<ion-row *ngFor="let item of extra" class="row-extra" id="extra-item-{{ item.id }}">

<ion-col width-10>

<ion-checkbox class="switcher display-block" color="secondary" [(ngModel)]="BookingConfirmationFormsState[item.id]" name="checkbox" [checked]="true"></ion-checkbox>

</ion-col>

<ion-col width-67 class="description">{{ item.description }}</ion-col>

<ion-col width-23 style="text-align: right;">

<div class="rate text-center display-block">FJ ${{ item.rate }}</div>

<div class="qty text-center display-block"><input type="number" min="1" max="100" class="text-center" [(ngModel)]="BookingConfirmationFormsQty[item.id]" name="qty" /></div>

</ion-col>

</ion-row>

<ion-row>

<ion-col>

<ion-col width-100 class="text-center"><button type="submit" class="continue">Continue</button></ion-col>

</ion-col>

</ion-row>

</form>

TypeScript

export class BookingEnhancementPage {

BookingConfirmationFormsState35: string;

BookingConfirmationFormsState36: string;

BookingConfirmationFormsState37: string;

BookingConfirmationFormsQty35: number;

BookingConfirmationFormsQty36: number;

BookingConfirmationFormsQty37: number;

constructor(public navCtrl: NavController, public navParams: NavParams, public loadingCtrl: LoadingController, private formBuilder: FormBuilder ) {}

ContinueBookingConfirmation(){

console.log( this.BookingConfirmationFormsState35 );

console.log( this.BookingConfirmationFormsState36 );

console.log( this.BookingConfirmationFormsState37 );

}

}

相关阅读:
Top