calling a method of service from Page loaded or navigated event causing below error
TypeError: Cannot read property 'apply' of undefined
File: "file:///data/data/org.nativescript.preview/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js, line: 142, column: 24
StackTrace:
Frame: function:'invoke', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/timer/timer.js', line: 19, column: 47
Frame: function:'ZoneDelegate.invoke', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 365, column: 26
Frame: function:'Zone.runGuarded', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 138, column: 47
Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js', line: 116, column: 29
Frame: function:'run', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/timer/timer.js', line: 23, column: 13
here is playground demo to reproduce the error.
https://play.nativescript.org/?template=play-ng&id=r2C7nK&v=3
@bhavincb we've recently updated the Playground to use the latest nativescript-angular version and with that change, the demo is working as expected on my side.
[Nexus 5X]: working perfectly
hii @NickIliev ,
sorry for adding wrong demo. i had updated demo link. please check it again from your side.
here is link.
https://play.nativescript.org/?template=play-ng&id=r2C7nK&v=3
@bhavincb the setTimeout callback is causing your issue. Either wrap the execution in the Angular zone or run the wanted method in the setTimoput callback as follows:
setTimeout(() => {
this.startUploading();
}, 100);
Example while using zone to wrap an execution of a code outside the Angular zone.
constructor(private page: Page, private uploadReq: HomeService, private _zone: NgZone) {
this.page.on(Page.loadedEvent, event => {
this._zone.run(() => {
this.uploadReq.uploadImages();
})
});
}
Most helpful comment
Example while using zone to wrap an execution of a code outside the Angular zone.