SerzN1 SerzN1 - 9 months ago 23
AngularJS Question

How to organize the download of data with the authorization check in Angular?

When you step on the rout triggered a particular controller and loads the data.

angular.module('app.Images', [])

.controller('ImagesCtrl', function($scope, $http, $window, imagesUrl) {
var _this = this;

this.images = {};


function checkResponse (data) {
if (data.success && {
_this.images =;
} else if (data.error) {
} else if (data.reload) {

On each route have to check

How best to do data load and such checks at all entry points?

Thanks for the answers.


If You need to globally check the data.reload (if i understand You correctly) then You can user interceptors ($httpProvider.interceptors). You can read about it here in the interceptors part.

$httpProvider.interceptors.push(['$q', function ($q) {
  return {
    'response': function(result) {
      //check data.reload here
      return $q.resolve(result);