-2

i set variable ar at the first. like

export class HomePage {
ar:any;
 ... 
 ...
constructor( ...){
 ar=new Array();
...
this.loadEvent();
}

and then, on triggered function of constructor,

enter image description here

I tweaked above function to below

enter image description here

Why can't I put values from firebase to variable ar?

Pedro J
  • 281
  • 5
  • 14
  • Hey it's generally a better idea to post your actual code rather than screenshots of it. It makes it easier for people to answer your question. – m0meni Sep 17 '18 at 23:23
  • Also since it looks like you're using VSCode, you might want to install this: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode extension that'll format your code for you. Right now it's a little hard to read – m0meni Sep 17 '18 at 23:25
  • A good read: https://stackoverflow.com/a/20279485/2864740 – user2864740 Sep 17 '18 at 23:38

1 Answers1

2

That's happening because this inside your function passed to .then is different from this outside your function. Read https://yehudakatz.com/2011/08/11/understanding-javascript-function-invocation-and-this/ for a good explanation on why.

To fix this instead of

function (snapshot) {}

you need to do

(snapshot) => {}

which maintains the value of this from the outer scope.

m0meni
  • 16,006
  • 16
  • 82
  • 141