ユーザーが認証を必要とするAPIへの呼び出しをトリガーした場合にのみログインダイアログを表示する遅延認証を実装しようとしています。私はブートストラップui.bootstrap.modal (およびモーダル内のui.bootstrap.alert ) を使用しています。問題は、これらのディレクティブが以下を明示的に指定していることですteamplateUrl
:
- template/modal/backdrop.html (
modal.js
ここにあります) - template/modal/window.html (
modal.js
ここにあります) - template/alert/alert.html (
alert.js
ここにあります)
このような:
.directive('modalBackdrop', ['$timeout', function ($timeout) {
return {
restrict: 'EA',
replace: true,
templateUrl: 'template/modal/backdrop.html',
link: function (scope, element, attrs) {
/* ... */
}
};
}])
$modal.open()
そして、私が呼び出して ui-bootstrap が新しいモーダル ウィンドウの DOM を構築するたびに、Angular は、テンプレートがメソッドまたはタグの追加$http
によって既に読み込まれている場合でも、サービスを介してこれらの URL を解決しようとします。これは基本的に、インターセプターで無限再帰を引き起こし、上記の URL のオーバーロードでログイン ダイアログを表示しようとします。$templateCache.put
<script>
request
これが私のインターセプターの簡略化されたバージョンです:
.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;
}
}}]);
動作デモはこちら
ui.bootstrap.modal
とで使用される templateUrls のハードコーディングを含まないアプローチをアドバイスできますui.bootstrap.alert
か?
また、これを githubの問題として報告しました。