Skip to content

Instantly share code, notes, and snippets.

@kkurni
kkurni / httpLoadingInterceptor
Last active December 13, 2015 18:49
AngularJS Loading interceptor example
KK.factory('httploadingInterceptor',['$q','$rootScope', function ($q, $rootScope) {
return function (promise) {
$rootScope.loading = true;
return promise.then(function (response) {
// hide the spinner
$rootScope.loading = false;
return response;
@kkurni
kkurni / TokenHandler.js
Last active December 11, 2015 21:28
Angular JS Factory for Token Handler which inject authorization header request. This must use in combination with my custom resource which modified based on 1.1.2 - https://gist.github.com/4662478
KK.factory('TokenHandler', ['$cookieStore', function ($cookieStore) {
var tokenHandler = {};
tokenHandler.setToken = function (newToken) {
$cookieStore.put("X-Authorization-Token", newToken);
console.log('set token ' + newToken);
};
tokenHandler.getToken = function () {
console.log('get cookie ' + $cookieStore.get("X-Authorization-Token"));
@kkurni
kkurni / kk-angular-resource-1.1.2
Last active December 11, 2015 21:28
AngularJS Resouce (1.1.2) with custom header params. Example to use. Authenticate.signIn(null,null, function (data, headers) { console.log(headers('x-token')); }, function(data, status, headers, config) { console.log('fail'); }, { 'Authorization': 'Basic dGVzdGtrMTNAdGVzdC5jb206cGFzc3dvcmQhMQ==' } );
'use strict';
/**
* @ngdoc overview
* @name ngResource
* @description
*/
/**
* @ngdoc object
@nblumoe
nblumoe / angularjs_resource_tokenhandler.js
Created July 5, 2012 07:34
AngularJS service to send auth token with $resource requests
.factory('TokenHandler', function() {
var tokenHandler = {};
var token = "none";
tokenHandler.set = function( newToken ) {
token = newToken;
};
tokenHandler.get = function() {
return token;