Answer the question
In order to leave comments, you need to log in
How to organize data loading with authorization check in Angular?
There was such a question. When entering the route, a certain controller is triggered and loads the data.
The code:
angular.module('app.Images', [])
.controller('ImagesCtrl', function($scope, $http, $window, imagesUrl) {
var _this = this;
$scope.images = {};
$http.get(imagesUrl)
.success(checkResponse);
function checkResponse (data) {
if (data.success && data.data) {
$scope.images = data.data;
} else if (data.error) {
alert(data.error);
} else if (data.reload) {
$window.location.reload(true);
}
}
data.reload
. Answer the question
In order to leave comments, you need to log in
You can add a $http response interceptor, globally or for specific requests.
Sample global interceptor response:
$httpProvider.interceptors.push(function($window) {
return {
response: function(response) {
if(response.data && response.data.reload) {
$window.location.reload(true);
}
}
};
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question