I had a similar problem when I needed a specific service in a callback in the configuration block, but I did not have access to the callback provider. I found that injecting the $ injector into the configuration block itself does not work, because the installation of the service is not guaranteed, and most likely it seems to you that you get the state of the nozzle from the moment you start config, and not when calling the callback. Given that I could not change the actual callback to always inject the injector directly, the only way to make it work is to grab the injector from dom. So you will get something like this (pay attention to the styles of the ES6 class!) ...
class AppAuth { static configure($authProvider) { $authProvider.configure({ apiUrl: '', handleAccountUpdateResponse: (response) => { const injector = angular.element(document.getElementById('app')).injector(); const Client = injector.get('Client'); response.data.clients.forEach((client, index, clients) => { clients[index] = new Client(client); }); return response; } }) } } export default AppAuth
A bit hacked, but the requirement is pretty standard, I wrap the related records (clients in the example) with the local model shell (Client). The library (ng-token-auth) sets the callback to the configuration block and wants to have a direct function with one parameter, without the ability to pass $ to the injector. Hope this helps someone with a similar situation.
source share