ブートストラップモードを自動的に表示するという簡単な指示がありますか? Bootstrap 3では、彼らはモーダルを自動的に表示する能力を失ったので、ng-ifのショーブロックを使用することはできません。どんな助けも素晴らしいだろう。ブートストラップモードのための単純な角度指令
答えて
は角1.2 &ブートストラップ3.1.1のための更新:http://embed.plnkr.co/WJBp7A6M3RB1MLERDXSS/
ディレクティブは孤立スコープを持っていないので、私はEnder2050の答えを拡張しました。つまり、モーダルコンテンツにスコープオブジェクトへの参照を含めることができます。また、ディレクティブ属性を再利用して、1つの属性だけが必要となります。
app.directive("modalShow", function ($parse) {
return {
restrict: "A",
link: function (scope, element, attrs) {
//Hide or show the modal
scope.showModal = function (visible, elem) {
if (!elem)
elem = element;
if (visible)
$(elem).modal("show");
else
$(elem).modal("hide");
}
//Watch for changes to the modal-visible attribute
scope.$watch(attrs.modalShow, function (newValue, oldValue) {
scope.showModal(newValue, attrs.$$element);
});
//Update the visible value when the dialog is closed through UI actions (Ok, cancel, etc.)
$(element).bind("hide.bs.modal", function() {
$parse(attrs.modalShow).assign(scope, false);
if (!scope.$$phase && !scope.$root.$$phase)
scope.$apply();
});
}
};
});
使用法:
<div modal-show="showDialog" class="modal fade"> ...bootstrap modal... </div>
ここには、ブートストラップモードを隠して表示するAngularディレクティブがあります。
app.directive("modalShow", function() {
return {
restrict: "A",
scope: {
modalVisible: "="
},
link: function (scope, element, attrs) {
//Hide or show the modal
scope.showModal = function (visible) {
if (visible)
{
element.modal("show");
}
else
{
element.modal("hide");
}
}
//Check to see if the modal-visible attribute exists
if (!attrs.modalVisible)
{
//The attribute isn't defined, show the modal by default
scope.showModal(true);
}
else
{
//Watch for changes to the modal-visible attribute
scope.$watch("modalVisible", function (newValue, oldValue) {
scope.showModal(newValue);
});
//Update the visible value when the dialog is closed through UI actions (Ok, cancel, etc.)
element.bind("hide.bs.modal", function() {
scope.modalVisible = false;
if (!scope.$$phase && !scope.$root.$$phase)
scope.$apply();
});
}
}
};
});
使用例#1 - これはあなたがモーダルを表示したいと仮定し - これはモーダルで角度の式を使用しています - あなたは条件
<div modal-show class="modal fade"> ...bootstrap modal... </div>
使用例#2としてNG-IFを追加することができます-visible属性
<div modal-show modal-visible="showDialog" class="modal fade"> ...bootstrap modal... </div>
他の例 - コントローラとの対話をデモするために、あなたはあなたのコントローラにこのような何かを追加することができ、それが2秒後にモーダルを表示し、5 secon後にそれを隠しますds。
$scope.showDialog = false;
$timeout(function() { $scope.showDialog = true; }, 2000)
$timeout(function() { $scope.showDialog = false; }, 5000)
私が他の解決方法を思いつくのは心配です。乾杯!
はちょうどこの中に差し込まれ、それは素晴らしい作品。高速応答とBootstrap 4へのリンクをありがとう: – Lereveme
"大きなライブラリーを今は入れたくありません" - jQueryとBootstrapのJavaScriptを含めることにしました... ehhh ... –
これはしかし、それはコントローラのスコープ内でshowDialogを回しませんし、popaloverを閉じた後に再びmodal-visible属性をfalseに戻します。 DOMからのみ消えますが、その変更はモデルに反映されません。 どうすればよいですか? –
- 1. 簡単な角度指令
- 2. 角度指令
- 3. ドロップダウン指令角度
- 4. 角度指令テンプレートの不明なスコープ
- 5. FacebookのコメントIon Appの角度指令
- 6. 角度指令テーブルの行の問題
- 7. コントローラからの角度指令関数
- 8. サービスを使った角度指令のユニットテスト
- 9. 動的コンテンツを使用した角度指令
- 10. 新しいカスタム角度指令が機能しない
- 11. ngRepeatの配列要素からの角度指令
- 12. 角度:ng-repeatの項目を指令に渡します
- 13. 角度指令:親スコープ内の変数にバインド
- 14. 角度指令のD3要素を追加する
- 15. 角度材料のページ区切り指令
- 16. templateUrlによる角度指令 - Plunkerの問題?
- 17. 角度2の指令定義を上書きする方法
- 18. AngularJS指令が私の見解は単純ですテンプレート
- 19. 適度に単純なTCPサーバーのための良いアーキテクチャ
- 20. 角度:どのようにこのような単純な角度のモジュールを考えると、コントローラ
- 21. thymleafの変数に格納された角度指令を使用する
- 22. 角度指令に補間値を設定する方法は?
- 23. 角度の狂った角度をテストするための角度計
- 24. 単純なカードゲームのためのPythonネットワーキングライブラリ
- 25. 単純なクエリのためのHibernate
- 26. 変数内の変数をhtmlの角度指令に渡します
- 27. 遅延読み込みWebpackチャンクとしてのui-routerの角度指令
- 28. 角度2 Modelbinding(文字列)を単純ために、私は文字列フィールドの入力との単純なコンポーネントまし
- 29. $ mdDiaogのような角型プロバイダ/工場/指令
- 30. 単純凸と単純非凸多角形の差
これは、(DOMツリーのモーダルの場所のために)ブートストラップのNavbarの後ろにモーダルが消えてしまうことを除いて、魅力的に機能します。 $(elem).modal( "show")を$(elem).appendTo( 'body')。modal( "show")に変更して解決しました。 –