[英]Make the browser wait for api response / http call response in angularjs
I tried the $q
service as follows but the browser still not waiting for the response. 我按以下方式尝试了$q
服务,但浏览器仍然没有等待响应。 I already spent almost a day to figure out a solution, I also tried the $timeout
. 我已经花了将近一天的时间来找出解决方案,我还尝试了$timeout
。
login.controller("loginCtrl", ['$scope', '$rootScope', '$filter', '$window', '$http', 'APIService', 'localStorageService', 'doAlert', '$translate', '$q', '$timeout',
function ($scope, $rootScope, $filter, $window, $http, APIService, localStorageService, doAlert, $translate, $q, $timeout) {
$scope.isLogOut = true;
$(window).unload(function () {
$rootScope.$broadcast('onUnload');
});
$scope.$on('onUnload', function (e) {
var deferred = $q.defer();
$http.get(url).
success(function (data, status, headers, config) {
deferred.resolve(data);
}).
error(function (data, status, headers, config) {
deferred.reject(status);
});
return deferred.promise;
});
Here is a sample where I use a callback to process data back from my utility 这是一个示例,我在其中使用回调来处理从实用程序返回的数据
function get(url, callback, obj) {
$http.get(url, obj)
.then(function (response) {
callback(response.data);
}, function () {
notification.error(PLEASE_CONTACT_SYS_ADMIN);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.