I'm new to typescript. I've tried searching through answers here but none of the solutions seem to fit.
I have a relatively simple (I guess) problem. The data that I get with profilesArr arrays are correct, but I can't seem to pass that data to the array "profiles" that I declared at the start of the class. It does, however, pass the data from profilesArr correctly to the locally declared array called "array". I can obtain the data from "array" easily, but when I run this line of code this.profiles[i]=profilesArr[k]; it gives me the error: Cannot read property 'profiles' of null.
export class RegisteredusersPage {
private profileListRef = this.db.list<Profile>('profile-list');
constructor(public navCtrl: NavController, public navParams: NavParams, private storage: Storage,
private db: AngularFireDatabase) {
}
profiles=[];
ionViewDidLoad() {
console.log('ionViewDidLoad RegisteredusersPage');
}
getProfile(){
console.log(this.db.list('profile-list'));
var database = firebase.database();
var ref=database.ref("profile-list");
ref.on('value', this.gotData, this.errData)
}
gotData(data){
console.log(data.val());
var profilesArr=data.val();
var keys=Object.keys(profilesArr);
var that=this;
var array=[];
console.log("Pre keys");
console.log("keys:"+keys);
console.log("profilesArr: "+profilesArr);
for(var i = 0; i <keys.length; i++){
var k = keys[i];
var profileName = profilesArr[k].name;
var profileCountry = profilesArr[k].country;
console.log(profileName,profileCountry);
alert(profileName);
alert(profileCountry);
array[i]=profilesArr[k];
this.profiles[i]=profilesArr[k];
}
console.log(this.profiles);
}
errData(err){
console.log("Error");
console.log(err);
}
I know it's a pretty newbie question, but I can't get my head around it. I would be really grateful if you could help me solve it, thanks!