Update ngFor when all data is processed in SQL Storage

51 views
Skip to first unread message

timodi...@gmail.com

unread,
May 27, 2016, 12:24:09 PM5/27/16
to AngularJS
Hi,

i wanna store all my data in sql storage but i've got the problem when new data is available. The new data is stored successfully in the storage but before the save-process is finished the view is already loaded...
How can i solve this problem, that when all data is stored, my view is automatically been updated without reloading?
I hope you understood my problem and can help me.

TiDiDoDa

unread,
May 27, 2016, 12:29:12 PM5/27/16
to AngularJS
Here my view:
<ion-card *ngFor="let n of news">
...
</ion-card>

And the js-part:
this.storage.query("SELECT * FROM news ORDER BY created DESC LIMIT 15").then(
(response) => {
if(response.res.rows.length > 0){
for(let i = 0; i < response.res.rows.length; i++){
this.news.push(response.res.rows[i]);
}
}
}
); 

Maybe more informations for understanding:
I fetch data from web page, store it in sql storage and get the data with the above js-part from sql storage. Maybe anyone knows a better solution... 

Sander Elias

unread,
May 28, 2016, 5:39:04 AM5/28/16
to AngularJS
Hi TiDiDoDa,

Your storage event is generated outside angular's reach. You need to inform angular that it's about time to update the view. 
Most people will advise you to use $scope$apply in your response handler. My suggestion is that you use $scope.$evalAsync() in stead. That way you don't end up with extra digest cycles you probably can do without.

Regards
Sander

Chris Pawlukiewicz

unread,
May 30, 2016, 4:49:45 PM5/30/16
to AngularJS
What do you mean by SQL storage? Do you mean WebSQL? Or are you running SQL on a node server?

Sander Elias

unread,
May 30, 2016, 10:01:02 PM5/30/16
to AngularJS
Hi Chris,

The answer to that is not relevant for his question. However, as he is asking an ionic question, chances are very large that he is using Sqlite through a cordova plugin.

Regards
Sander
Reply all
Reply to author
Forward
0 new messages