У меня есть код, который я использую для проверки подключения к серверу. Мой код работает каждые 60 секунд. После запуска кода он создает сообщение, и это отображается на странице. Вот что я до сих пор:
Код, который проверяет:
$interval(function () {
us.isConnected().then(closeConnect, openConnect);
}, 60 * 1000);
Код, который выполняет проверку
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;
};
Что бы я хотел сделать, это простая функция, называемая retryMessage(), которая позволит мне дать такое сообщение:
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.
С числом секунд, отсчитывающимся до 0, когда будет проведена повторная проверка.
Может кто-нибудь предложить способ в AngularJS, чтобы я мог достичь этого обратного отсчета?