Created
November 7, 2014 15:15
-
-
Save josephfinlayson/37c0639645c96f9bf5c8 to your computer and use it in GitHub Desktop.
Pattern to combine ngProgress and ui router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work since ngProgress isn't instantiated inside
app.run