I have a service class that has a array of quests like so:
import { ObservableArray, ChangedData } from 'tns-core-modules/data/observable-array/observable-array';
quests: ObservableArray<Quest>;
I can push quests into the array like this:
let quest = new Quest(data.key, data.value["name"], data.value["description");
this.quests.push(quest);
In another class I subscribe to change events of that array:
this.myService.quests.on(ObservableArray.changeEvent,(args:ChangedData<Quest>) => {
console.log(args.object);
let quest: Quest = args.object; // can not cast to quest
});
In the log I can see that my data is inside the ChangeData. But I horribly fail to cast that back to my object.
How can I achieve that?
Thanks
let quest = <Quest> args.object;?(args:ChangedData<Quest>) =>make it(args) =>argsif of typeEventDataitsobjectproperty is of type element which raised the event. So you can't grab theQuestfrom its object. So you will be only notified by change detection. You can see this here docs.nativescript.org/core-concepts/events