Mam kod, którego używam do sprawdzania połączenia z serwerem. Mój kod jest uruchamiany co 60 sekund. Po uruchomieniu kodu tworzy on wiadomość, która pojawia się na stronie. Oto co mam do tej pory:Jak mogę wyświetlić komunikat odliczający co sekundę z AngularJS?
Kod, który sprawdza:
$interval(function() {
us.isConnected().then(closeConnect, openConnect);
}, 60 * 1000);
Kod, który robi Skontrolować
isConnected =(): ng.IPromise<any> => {
var self = this;
var deferred = this.$q.defer();
this.$http({
method: 'GET',
url: self.ac.baseUrl + '/api/Connect/Verify'
})
.success(() => {
self.connects = 0;
self.connectMessage = null;
deferred.resolve();
})
.error(() => {
if (self.connects == 0) {
self.connectMessage = "Unable to establish a connection to the server. " + retryMessage();
} else if (self.connects == 1) {
self.connectMessage = "Unable to establish a connection to the server for " + self.connects + " minute" + retryMessage();
} else {
self.connectMessage = "Unable to establish a connection to the server for " + self.connects + " minutes." + retryMessage();
}
self.connects++;
deferred.reject();
});
return deferred.promise;
};
Co chciałbym zrobić, to mieć prostą funkcję zwaną retryMessage(), które pozwolą mi przekazać wiadomość:
Unable to establish a connection to the server for 164 minutes.
Connection will be retried in 59 seconds.
Unable to establish a connection to the server for 164 minutes.
Connection will be retried in 58 seconds.
Unable to establish a connection to the server for 164 minutes.
Connection will be retried in 57 seconds.
...
Unable to establish a connection to the server for 164 minutes.
Connection will be retried in 1 seconds.
Unable to establish a connection to the server for 164 minutes.
Retrying connection now.
Unable to establish a connection to the server for 165 minutes.
Connection will be retried in 59 seconds.
Zliczanie sekund w dół do 0, kiedy nastąpi ponowne sprawdzenie.
Czy ktoś może zaproponować sposób w AngularJS, że mogę osiągnąć to odliczanie?
Zapoznaj się z Link, to prawie wszystkie liczniki można chcieć: http://siddii.github.io/angular-timer/ – eitanfar