How do you all save data to a service using TypeScript?
If I have a service like this:
class MyService {
persistentData: Object;
constructor() {
this.init();
}
private init = (): void => {
this.persistentData = {};
}
public saveData = (data): Object {
this.persistentData = data;
}
}
How would I go about keeping the data consistent through different routes? Each time a new route is called, the service class is instantiated again, and the persistentData object is reset to be blank. Normally in regular JavaScript you could do:
angular
.factory('myFactory', function() {
var persistentData = {};
return {
setFormData: function(newData) {
persistentData = newData;
}
}
})
And this works. I must be missing something, can anyone help?