I am trying to create a component in Angular 2 which displays data from a service. The service basically loads some data from a json file after some input from the user. I\'
Is it possibly caused by referencing assetService, the argument, and not this.assetService, in your views? Maybe that is causing Angular's change detection not to be triggered without calling zone.run().
This would require knowledge about the inner workings of the AssetService
you're using.
Angular runs the code of your components within its zone where most async APIs (addEventListener
, setTimeout
, ...) are patched so the zone can notify Angular when such an async callback has happend. This is when Angular runs change detection.
If you initialized AssetService
outside Angular or AssetService
by other means executes code outside Angulars zone, then Angular doesn't get notified about happened async callbacks and doesn't run change detection.
With zone.run(...)
you explicitely make code execute inside Angulars zone and change detection is run afterwards.