I’m currently investigating Ionic 3 using the simple template.
My project is running and i can get data from my windowsAzure database into an array ( i’m looking at doing the offline process later on )
As the processes are asynchronous there are a lot of ‘.then(…’ sections.
So here are some snipets of my code on a basic page…
myrows : any[] = []; //= Array<{text:string}>;
my: "hello";
_this = this;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.myrows = [];
//this.myrows.push({text:"dude"}); // added to try and see if the ngfor worked -- it did show this value
this.OnInit();
}
OnInit() {
console.log("so this is my starting code !");
client = new WindowsAzure.MobileServiceClient("https://MYURL.azurewebsites.net");
store = new WindowsAzure.MobileServiceSqliteStore('store.db');
store.defineTable({
name: 'todoitem',
columnDefinitions: {
id: 'string',
text: 'string',
deleted: 'boolean',
complete: 'boolean'
}
});
this.initializeStore();
}
showdata(){
//console.log("showData");
todoItemTable.where({ complete: false }) // Set up the query
.read() // Read the results
.then(item =>{this.mysuccess(item);
});
return true;
}
mysuccess(item){
console.log(item); // shows all my RAW data
item.forEach(_i =>{
console.log(_i.text);
this.myrows.push({text: _i.text}); // this is been added - shows in console.log!
})
console.log( this.myrows);
return this.myrows; // trying to force it to update the UI
}
initializeStore() {
// table = client.getTable("todoitem");
syncContext = client.getSyncContext();
todoItemTable = client.getSyncTable('todoitem');
syncContext.initialize(store).then(() => {
console.log("So what !");
syncContext
.pull(new WindowsAzure.Query('todoitem' /* table name */), 'all_todo_items' /* unique queryId */)
}) .then(() =>this.showdata());
}// end initaliseStore
itemTapped(item) {
// That's right, we're pushing to ourselves!
console.log(item);
}
the html is very basic
<ion-list>
{{myrows}}
<button ion-item *ngFor="let r of myrows" (click)="itemTapped(r)">
{{r.text}}
</button>
</ion-list>
When i click on an item - itemTapped - the lost then updates on the page!!!
Please - why will it not update as the array has data pushed to it…
I have an ionic v1 project and that behaved better than this!