1

I'm trying to load the google charts library. I declared google as a global variable using the following piece of code:

declare var google:any;

Now, in ngOnInit(), I'm doing

google.charts.load('current',{packages:['geochart']);
google.charts.setOnLoadCallback(this.drawMap());

And, now, in drawMap():

console.log("google", this.google);
console.log("google.visualization", this.google.visualization);

The weirdest thing happened: The Weird Angular Bug

How is it possible for an object to have property in one line and that property is undefined in the next line..?

Faizuddin Mohammed
  • 4,118
  • 5
  • 27
  • 51
  • Can you debug your code by placing an breakpoint ? – Vinod Louis Apr 05 '17 at 06:53
  • 1
    It's this issue: [*console.log of element.children shows 0 length but has three entries when expanded later*](http://stackoverflow.com/questions/38660832/element-children-has-elements-but-returns-empty-htmlcollection). The property **wasn't** there when those `console.log` statements ran, it was added later. You'll see what's really going on if you use the debugger as @VinodLouis suggested, since it will actually stop execution at the point where you're logging. – T.J. Crowder Apr 05 '17 at 06:54
  • When you hover over the small blue `i` behind the first `console.log` you see that the context has been changed. This is maybe the reason. Do you do async functions in the moment? Try to debug these console.logs, to ensure that `google` contains the right members. In Addition i cannot see the `visualization` mentioned in the first line `Object {charts: Object}`, but all Members are mentionen in the last line `Response {_body: ProgressEvent, status: 0 ... }` maybe the visualization is not enumerable. – DomeTune Apr 05 '17 at 06:55
  • 1
    @T.J.Crowder I think that is definitely the issue. I'll add break points and see. as Vinod Louis suggested – Faizuddin Mohammed Apr 05 '17 at 06:57
  • 1
    I'll test this and post the results. – Faizuddin Mohammed Apr 05 '17 at 06:58
  • The issue was, I was doing `this.drawMap()` instead of `this.drawMap`. Calling instead of passing. At least a dozen down votes for this. – Faizuddin Mohammed Apr 05 '17 at 07:34

0 Answers0