0

I have a simple problem with my Ionic app.

So I have this code:

export class HomePage {
  devices: string[];
  stuff: string;
  constructor(public navCtrl: NavController) { };

  ionViewWillEnter() {
    this.devices.push('Roletor3000');
    this.stuff = 'test';
  }
}

And for some reason I get an error that this.devices does not exist. But this.stuff works just fine. What am I doing wrong here?

1 Answer 1

2

You need to instantiate your array like so:

export class HomePage {
  devices: string[] = [];
  stuff: string;
  constructor(public navCtrl: NavController) { };

  ionViewWillEnter() {
    this.devices.push('Roletor3000');
    this.stuff = 'test';
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Wow thanks. Still lost with TypeScript a bit. Will select as best in 12 min
Glad i could help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.