I'm trying to implement lazy authorization which will bring in the login dialog only when user triggers call to API requiring authentication. I'm using bootstrap ui.bootstrap.modal (and ui.bootstrap.alert within the modal). The problem is that these directives explicitly specify following teamplateUrl's:
- template/modal/backdrop.html (in
modal.jshere) - template/modal/window.html (in
modal.jshere) - template/alert/alert.html (in
alert.jshere)
like this:
.directive('modalBackdrop', ['$timeout', function ($timeout) {
return {
restrict: 'EA',
replace: true,
templateUrl: 'template/modal/backdrop.html',
link: function (scope, element, attrs) {
/* ... */
}
};
}])
And every time I'm calling $modal.open() and ui-bootstrap builds DOM for new modal window, angular tries to resolve those urls via $http service even though the templates are already loaded either by $templateCache.put method or by adding a <script> tag.
This is basically causing infinite recursion in my interceptor which tries to bring in login dialog in request overload for the urls above.
Here is simplified version of my interceptor:
.config(['$provide', '$httpProvider', function($provide, $httpProvider) {
$provide.factory('testInterceptor', ['$injector', function($injector) {
return {
'request': function(config) {
var auth = $injector.get('authService');
var modal = $injector.get('$modal');
if (!auth.LoggedIn) {
var loginModal = modal.open({
template: 'Login screen <alert type="warning">some message</alert>',
});
return loginModal.result;
}
return config;
}
}}]);
Working demo is here
Can anyone advise the approach which will not involve hard-coding of the templateUrls used in ui.bootstrap.modal and ui.bootstrap.alert?
I've also reported this as an issue on github.
$injector.get('$modal')configsection which supports only providers injection (see documentation)