Make the browser wait for api response / http call response in angularjs -
i tried $q
service follows browser still not waiting response. spent day figure out solution, tried $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 sample use callback process data utility
function get(url, callback, obj) { $http.get(url, obj) .then(function (response) { callback(response.data); }, function () { notification.error(please_contact_sys_admin); }); }
Comments
Post a Comment