简体   繁体   中英

How to refresh the content in the Div?

The project i am working is in angularjs, the data in the back end changes in 30 second, I have to reflect the changes done. I should refresh the Div every 10 seconds, any ideas how to do it?

You must have written someCallBak for your data coming from backend , you must storing a variable there to show it in you Div and there must a timer to call the data from backend . You can write a variable :

 function yourCallback(){
     $scope.showDiv = false;

       your data come {
  //make it true
$scope.showDiv = true;
 }}

Write this variable in your div ng-if="showDiv";

you need to think about your client-server model. You need to decide how you want to get the data from your backend to update the frontend, (lazy load, socket, laid load) it's up to you.

Your frontend needs to have a layer to connect to the backend, retrieve data and update the view.

About the 30 seconds thingy, you cannot think of those 30 seconds on the frontend as the client could connect in second 29 for example. If you want to be accurate, you need to notify the frontend that there's an update (maybe a socket connection), but if the update time is not critical you can decide to pull with ajax every maybe X seconds to have a good average.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM