I am stuck with an error and need some help. I have declared variables like this:
jdetails: Array<any>;
cards: Array<any>;
This is the method I am using:
ionViewDidLoad() {
console.log('ionViewDidLoad FeedsPage');
//for new card
this.addnewcard();
console.log(this.cards);
}
addnewcard() {
this.jobdetail.getJobDetails().then((data) => {
//console.log(data);
this.jdetails = data;
});
for (let val of this.jdetails) {
this.cards.push(val);
}
}
Whenever I press a button, the "voteUp" method gets executed.
voteUp() {
let removedcard = this.cards.pop();
this.addnewcard();
}
Unfortunately, I am encountering a type error.
ERROR TypeError: Cannot read property ‘length’ of undefined at FeedsPage.webpackJsonp.260.FeedsPage.addnewcard (feeds.ts:171) at FeedsPage.webpackJsonp.260.FeedsPage.ionViewDidLoad (feeds.ts:63) at ViewController._lifecycle (view-controller.js:486) at ViewController._didLoad (view-controller.js:369) at NavControllerBase._didLoad (nav-controller-base.js:768) at t.invoke (polyfills.js:3) at Object.onInvoke (core.js:4749) at t.invoke (polyfills.js:3) at r.run (polyfills.js:3) at NgZone.run (core.js:4566)