0
我一直在試圖讓Bootstrap模型在加載時隱藏,然後在單擊按鈕後顯示它,但迄今爲止一直未成功。對於AngularJS我很新,所以如果我沒有正確地做到這一點,請耐心等待。下面是我到目前爲止有:使用AngularJS切換Twitter Bootstrap(3.x)模式
模態角指令(modal.js):
angular.module('my.modal', ['modal.html'])
.directive('myModal', function() {
return {
restrict: 'E',
transclude: true,
replace: false,
templateUrl: 'modal.html',
link: function(scope, element, attrs) {
element.modal('hide')
scope.toggleModal = function() {
if (attrs.showModal === true) {
element.modal('hide')
attrs.showModal = false
} else {
element.modal('show')
attrs.showModal = true
}
}
}
};
});
莫代爾模板(modal.html):
<div id="{{id}}" showModal="false" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
<div class="content" ng-transclude></div>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="showModal = false">Cancel</button>
</div>
</div>
</div>
</div>
最後,按鈕切換模式(的index.html):
...
<my-modal>
<p>Some content</p>
</my-modal>
<button class="btn btn-default" type="button" ng-click="toggleModal()">Toggle me!</button>
...
所有這樣做是顯示在頁面加載模式(我的頭和所有的行吟詩人之間r內容,所以它不會浮在任何東西之上)並且切換按鈕不起作用。
如果您可以使用另一個庫,我建議您查看[UI Bootstrap](http://angular-ui.github.io/bootstrap/)。它爲您提供Bootstrap指令和服務。 – 2015-02-09 22:08:07
showModal是不變的,永遠不會改變。嘗試使用'ng-show =「showModal」'。 – h7r 2015-02-09 22:13:40
我想過使用UI Bootstrap,但後來我想不出做一個跨越式的方法。對此有何想法? – tugayac 2015-02-10 03:46:52