Can't get checkbox values to a <bool> array

Hello, I’m trying to get the correct ngModel syntax for a dynamically set list of checkboxes, which take info from a custom class (MultipleChoice). However, I have been stuck with this error: TypeError: Cannot read property '0' of undefined.


export class MultipleChoice {
	questionId: number;
	questionText: string;
	itemList: Array<string>;
	isChecked: Array<boolean>;

		questionId: number,
		questionText: string,
		itemList: Array<string>,
		isChecked?: Array<boolean>

	) {
		this.questionId = questionId; 
		this.questionText = questionText;
		this.itemList = itemList;


    import {Platform, NavController} from 'ionic-angular';
    import {Component} from '@angular/core';
    import {MultipleChoice} from './../../classes/questionClass/questionClass';

      templateUrl: 'build/pages/test/test.html'

    export class MultipleDirective {
      public question = new MultipleChoice(0,'Expected working hours?',['All hours','9:00 to 17:00','All the weekdays', 'During weekend']);
      constructor(private navController: NavController) { }

  public nextQuestion() {
// TypeError: Cannot read property '0' of undefined 
    this.question.isChecked.forEach((check) => {


<ion-navbar *navbar>

<ion-content padding class="test">
    {{question .questionText}}
  <ion-item *ngFor="let item of question.itemList; let i = index">
    <ion-checkbox (ngModel)="question.isChecked[i]" ></ion-checkbox>

<button block (click)="nextQuestion()">Next</button>

1 Like