0
$q
サービスを次のように試みましたが、ブラウザはまだ応答を待っていません。私はすでにソリューションを見つけ出すためにほぼ一日を費やしましたが、私も$timeout
を試しました。 `$ http`alreadyは約束を返します。ここではブラウザがanglejsのapi応答/ http呼び出し応答を待つようにします
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;
});
をデータを処理するためにコールバックを使用したサンプルです。ですから、 '$ q'の必要はありません。 – Aer0
これも試しました。しかし、幸運はありません。$ http.get(url).success(function(response){ response.data; }); – user2617611
成功とエラーの代わりに '$ http.then(function(success){...}、function(error){...})'を使います。また、ドキュメントを見てみることもできます:https://docs.angularjs.org/api/ng/service/$http – Aer0