简体   繁体   中英

Progress bar display in angularjs

I have a web api server which counts 1 to 100 and the thread sleeps one second.

int count=0;
for (int i = 0; i < 100; i++)
{
   Thread.Sleep(1000);
   count++;
   ProgressReportAngular(count);
}

I would like to display the value of count in every second in Angularjs.(as progress bar) May I use for this Async Tasks? Should I push count value from web api to angularjs anywhere? How does it work?

I'm pretty sure I gave you the answer to this yesterday on your other account, but I'll repeat a short version here for your convenience.

You cannot push messages from ASP.NET Web Api to angular by using those frameworks alone. If Angular need data from the server, Angular needs to request this from the server. If you want to push messages from the server to the client, you'll need to use something like SignalR or Websockets. If you don't want to use those, you'll have to set up a periodic timer in Angular, eg by using JavaScripts setInterval() -method, where you have angular make a request for the current count from the web api.

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