jibon57 / nativescript-mediafilepicker

A complete file picker solution for NativeScript
Apache License 2.0
51 stars 36 forks source link

Mediafilepicker and Nativescript + Angular - run inside NgZone #110

Closed rallets closed 4 years ago

rallets commented 4 years ago

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!

jibon57 commented 4 years ago

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();

rallets commented 4 years ago

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.

aosi87 commented 4 years ago

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.