jibon57/nativescript-mediafilepicker

Mediafilepicker and Nativescript + Angular - run inside NgZone

Closed this issue · 3 comments

Hi, first thanks for your library, it saved me many headaches!
Just to help other developers using your library and Nativescript + Angular, I would like to let them know that the events are running outside the ngZone lifecycle.
I think because of the "javascript way" it's written.
I spent hours tring to figure out why the UI was not refreshed.
Reference: https://angular.io/api/core/NgZone

I solved in this way

mediafilepicker.on("getFiles", event => {
	this._ngZone.run(() => {
		// do your stuff here
		// any UI changes will be reflected
	});
});

Hope this help!

I think most of the developer who are working with NativeScript + Angular know that. Anyway thanks
Or ChangeDetectorRef from @angular/core will work too. Like this._cd.detectChanges();

Not really, I'm working with angular in enterprise applications from many years and used/using a lot of plugins, this is the first time I needed to use ngZone. Maybe because they are angular-compatible.
ChangeDetectorRef didn't work, it was my the first try.
I also created a PR to add a comment in the readme.

Mate, you need to read how angular works behind scenes, ngZone is a must, like angular life cycles, and how the compiler works, there is also a really good explanation why structural directives work like that.