Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Created January 21, 2015 16:27
Show Gist options
  • Save simonmorley/67ee511ab09a79da3498 to your computer and use it in GitHub Desktop.
Save simonmorley/67ee511ab09a79da3498 to your computer and use it in GitHub Desktop.
medium, creating an interceptor to device device types
app.factory('apInterceptor', ['$q', '$location', '$rootScope', '$routeParams', 'DEVICES',
function($q, $location, $rootScope, $routeParams, DEVICES) {
return {
request: function(config) {
var setDevice = function() {
if ($routeParams.uamip !== undefined && $routeParams.uamport !== undefined) {
$rootScope.deviceId = DEVICES.ct;
} else if ( $routeParams.switchip !== undefined && $routeParams.cmd !== undefined ) {
$rootScope.deviceId = DEVICES.aruba;
} else if ( $routeParams.login_url !== undefined && $routeParams.ap_tags !== undefined) {
$rootScope.deviceId = DEVICES.meraki;
}
};
$rootScope.$on('$routeChangeSuccess', function () {
if ($rootScope.deviceId === undefined) {
setDevice();
}
});
return config;
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment