Skip to content

Instantly share code, notes, and snippets.

@josephfinlayson
Created November 7, 2014 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephfinlayson/37c0639645c96f9bf5c8 to your computer and use it in GitHub Desktop.
Save josephfinlayson/37c0639645c96f9bf5c8 to your computer and use it in GitHub Desktop.
Pattern to combine ngProgress and ui router
'use strict';
angular.module('something', [
'deps'
])
.config(function($locationProvider) {
$locationProvider.html5Mode(true);
})
.config(function($provide) {
return $provide.decorator('$uiViewScroll', function($delegate, $window) {
return function(uiViewElement) {
//eventually do something more intelligent with the uiViewElement
return $window.scrollTo(0, 0);
};
});
}).run(function($injector, ngProgress) {
var $rootScope = $injector.get('$rootScope');
// Sets the height of the progressbar. Use any valid CSS value Eg '10px', '1em' or '1%'.
// ngProgress.height();
// Sets the color of the progressbar and it's shadow. Use any valid HTML color
// ngProgress.color();
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState) {
ngProgress.start();
});
$rootScope.$on('$stateChangeSuccess', function() {
ngProgress.complete();
});
$rootScope.$on('$stateChangeError', function() {
ngProgress.done();
});
});
@mudassir0909
Copy link

This doesn't work since ngProgress isn't instantiated inside app.run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment