Within my 'app.js' file, I have the following code that is used in my config to set up
$navigationProvider.doSomething()
. When running this code, Test1 and Test3 are alerted correctly, but I'm having trouble with getting my this.$get method to work (none of the Test2 alerts are showing). Shouldn't it be called during the page initialization?
//providers.js
angular.module('myapp.providers', []).provider('$navigation', function() {
var routes = {};
function test () {
alert(arguments);
};
alert('Test1');
this.$get = ['$rootScope', '$location',
function( $rootScope, $location) {
$rootScope.$on('$locationChangeSuccess', function () {
alert('Test2');
});
alert('Test2');
return {};
}];
this.doSomething = function () {alert('Test3')};
});
//app.js
var app = angular.module('myapp', [
'myapp.providers'
]).config(function ($locationProvider, $navigationProvider) {
$navigationProvider.doSomething();
$locationProvider.html5Mode(true);
});
EDIT:
To make it work, I had to add a
.run(['$navigation'], function ($navigationProvider) {})
block to my 'myapp.providers' module. So my question now is why the provider isn't automatically initialized (considering it's configured in app.js)? Is there another way to ensure my provider gets initialized? Having an empty module.run()-block seems unnecessary!