我試圖使用ng-show,在Angular網站上顯示的示例(示例位於頁面的最底部)顯示自定義模態指令。但是,我沒有任何運氣讓它工作。不能使用ngShow動畫自定義指令
我正在使用Angular 1.3.x與Bootstrap 3.3.x.我沒有使用Angular UI Bootstrap,因爲自定義模態指令更符合我的需求。
這裏是我到目前爲止有:
Modal.js:
angular.module('plunker', [])
.directive('myModal', function() {
return {
restrict: 'E',
transclude: true,
replace: true,
templateUrl: 'modal.html',
controller: 'ModalCtrl',
link: function(scope, element, attrs) {
scope.showModal = false;
if (attrs.title === undefined) {
scope.title = 'Modal Title Placeholder';
} else {
scope.title = attrs.title;
}
scope.$watch('showModal', function(isHidden) {
if (isHidden) {
} else {
}
});
}
};
}).controller('ModalCtrl', ['$scope',
function($scope) {
$scope.$open = function() {
$scope.showModal = true;
};
$scope.$close = function() {
$scope.showModal = false;
};
}
]);
modal.html:
<div role="dialog" tabindex="-1" class="modal modal-fade" ng-show="showModal">
<div class="modal-backdrop" style="height: 100%"> </div>
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">{{title}}</h3>
</div>
<div class="modal-body">
<div class="content" ng-transclude></div>
</div>
</div>
</div>
</div>
modal.css:
.modal-fade {
opacity: 1;
display: block !important;
}
.modal-fade .ng-hide-add .ng-hide-add-active,
.modal-fade .ng-hide-remove .ng-hide-remove-active {
-webkit-transition: all linear 1s;
-moz-transition: all linear 1s;
transition: all linear 1s;
}
.modal-fade .ng-hide {
opacity: 0;
display: none;
}
index.html:
<my-modal title="Example Modal">
<p>Some text</p>
<button type="button" class="btn btn-primary" ng-click="$close()">Close</button>
</my-modal>
<button type="button" class="btn btn-primary" ng-click="$open()">Open Modal</button>
其他一切正常,即模態顯示並可以關閉,但沒有動畫。
這是Plunkr指向代碼的鏈接。
你可以扔掉這個在plunkr或的jsfiddle並鏈接了嗎? – Ninjarabbi 2015-02-11 23:08:49
當然!剛剛添加了上面的plunkr鏈接。 – tugayac 2015-02-12 03:45:37