Angular provider $ get not initialized

The following code is included in my app.js file and is used in my configuration to configure $navigationProvider.doSomething() . Test1 and Test3 are warned, but I cannot get this method. Get get works (any of Test2 test warnings). In my opinion, you need to call it to initialize my page, right?

//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:

I managed to get it working by adding the .run(['$navigation'], function ($navigationProvider) {}) block .run(['$navigation'], function ($navigationProvider) {}) to my myapp.providers module. Therefore, to point out my question a little more, why is there no automatic initialization (since I am setting up the provider in app.js)? Is there any other solution to initialize my provider? Empty module.run () - the block seems a little silly to me!

+4
source share
1 answer

You answer your question to a large extent. Configuration should take place at setup time and instantiation at run time. Otherwise, what is the meaning of the configuration phase?

0
source

Source: https://habr.com/ru/post/1482193/


All Articles