I am trying to extract data from a database and set it to a scope variable. This is inside a callback that does not work as an angular2 scope. I do not know why. I tried timeout zone. gas stuff, a promise. I don’t know what it is, so I can’t use it. Please help me figure this out.
listFriends(callback) {
result_data = [];
db.transaction(function(tx) {
tx.executeSql('SELECT * from mytable', [], function(tx, results) {
length = results.rows.length;
for (i = 0; i < length; i++) {
result_data.push(results.rows.item(i))
}
callback(result_data);
}, null);
});
}
public allmyFriends: any;
public self = this;
public test;
constructor(myFriendService: MyFriendService) {
this.myFriendService = myFriendService;
this.myFriendService.listFriends((response) => {
this.test="test working";
this.allmyFriends = response;
console.log("in list" + this.allmyFriends);
} );
}
source
share