Saving The Application State On Cordovas Pause With Angular
I've got a Cordova app running on my Android device to show some news retrieved from a web service. As I'm using Typescript and Angular I've got a service holding my news like so:
Solution 1:
When you define your event binding in
document.addEventListener('pause', this.saveNews, false);
your method is simply not declared yet. Take a look at this TypeScript example:
classTest {
greeting: string;
constructor(message: string) {
console.log(greet)
}
greet() {
return"Hello, " + this.greeting;
}
}
It transpiles to this JavaScript:
varTest = (function () {
functionTest(message) {
console.log(greet);
}
Test.prototype.greet = function () {
return"Hello, " + this.greeting;
};
returnTest;
})();
You would expect to get a function-reference, but hoisting wont work here, because every method is a reference for an anonymous function and the prototype-fields for these functions are simply not declared yet.
Encapsulate it in a lambda function will work:
document.addEventListener('pause', ()=>this.saveNews(), false);
Post a Comment for "Saving The Application State On Cordovas Pause With Angular"