我正在创建一个模式:
var modal = $modal.open({
templateUrl: "/partials/welcome",
controller: "welcomeCtrl",
backdrop: "static",
scope: $scope,
});
有没有办法增加其宽度?
我正在创建一个模式:
var modal = $modal.open({
templateUrl: "/partials/welcome",
controller: "welcomeCtrl",
backdrop: "static",
scope: $scope,
});
有没有办法增加其宽度?
Answers:
我使用这样的css类来定位modal-dialog类:
.app-modal-window .modal-dialog {
width: 500px;
}
然后在调用模式窗口的控制器中,设置windowClass:
$scope.modalButtonClick = function () {
var modalInstance = $modal.open({
templateUrl: 'App/Views/modalView.html',
controller: 'modalController',
windowClass: 'app-modal-window'
});
modalInstance.result.then(
//close
function (result) {
var a = result;
},
//dismiss
function (result) {
var a = result;
});
};
.modal-dialog
另一种简单的方法是使用2个预制大小,并在html中调用函数时将它们作为参数传递。使用:'lg'用于宽度为900px的大型模态'sm'用于宽度为300px的小型模态或不传递任何参数,则使用默认大小600px。
示例代码:
$scope.openModal = function (size) {
var modal = $modal.open({
templateUrl: "/partials/welcome",
controller: "welcomeCtrl",
backdrop: "static",
scope: $scope,
size: size,
});
modal.result.then(
//close
function (result) {
var a = result;
},
//dismiss
function (result) {
var a = result;
});
};
在html中,我将使用以下内容:
<button ng-click="openModal('lg')">open Modal</button>
您可以为.modal-lg类指定自定义宽度,专门用于您的弹出窗口,以实现更大的视口分辨率。这是操作方法:
CSS:
@media (min-width: 1400px){
.my-modal-popup .modal-lg {
width: 1308px;
}
}
JS:
var modal = $modal.open({
animation: true,
templateUrl: 'modalTemplate.html',
controller: 'modalController',
size: 'lg',
windowClass: 'my-modal-popup'
});
当我们打开一个模态时,它接受大小作为参数:
其大小的可能值: sm, md, lg
$scope.openModal = function (size) {
var modal = $modal.open({
size: size,
templateUrl: "/app/user/welcome.html",
......
});
}
HTML:
<button type="button"
class="btn btn-default"
ng-click="openModal('sm')">Small Modal</button>
<button type="button"
class="btn btn-default"
ng-click="openModal('md')">Medium Modal</button>
<button type="button"
class="btn btn-default"
ng-click="openModal('lg')">Large Modal</button>
如果需要任何特定大小,请在模型HTML上添加样式:
<style>.modal-dialog {width: 500px;} </style>
还有另一种方法,您不必覆盖uibModal类并在需要时使用它们:您可以使用自己的大小类型(例如“ xlg”)调用$ uibModal.open函数,然后定义一个名为“ modal-xlg”的类,如下所示:
.modal-xlg{
width:1200px;
}
调用$ uibModal.open为:
var modalInstance = $uibModal.open({
...
size: "xlg",
});
这将起作用。因为无论您将其作为大小引导程序传递的任何字符串都将其以“ modal-”开头,这将充当window类的角色。
我发现从Bootstrap-ui接管模板更加容易。我仍然将注释的HTML保留在原处,以显示更改的内容。
覆盖其默认模板:
<script type="text/ng-template" id="myDlgTemplateWrapper.html">
<div tabindex="-1" role="dialog" class="modal fade" ng-class="{in: animate}"
ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
<!-- <div class="modal-dialog"
ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"
>
<div class="modal-content" modal-transclude></div>
</div>-->
<div modal-transclude>
<!-- Your content goes here -->
</div>
</div>
</script>
修改对话框模板(请注意包含“ modal-dialog”类和“ modal-content”类的包装DIV):
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-dialog {{extraDlgClass}}"
style="width: {{width}}; max-width: {{maxWidth}}; min-width: {{minWidth}}; ">
<div class="modal-content">
<div class="modal-header bg-primary">
<h3>I am a more flexible modal!</h3>
</div>
<div class="modal-body"
style="min-height: {{minHeight}}; height: {{height}}; max-height {{maxHeight}}; ">
<p>Make me any size you want</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary" ng-click="ok()">OK</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</div>
</div>
</div>
</script>
然后使用您要更改的任何CSS类或样式参数调用模式(假设您已经在其他地方定义了“ app”):
<script type="text/javascript">
app.controller("myTest", ["$scope", "$modal", function ($scope, $modal)
{
// Adjust these with your parameters as needed
$scope.extraDlgClass = undefined;
$scope.width = "70%";
$scope.height = "200px";
$scope.maxWidth = undefined;
$scope.maxHeight = undefined;
$scope.minWidth = undefined;
$scope.minHeight = undefined;
$scope.open = function ()
{
$scope.modalInstance = $modal.open(
{
backdrop: 'static',
keyboard: false,
modalFade: true,
templateUrl: "myModalContent.html",
windowTemplateUrl: "myDlgTemplateWrapper.html",
scope: $scope,
//size: size, - overwritten by the extraDlgClass below (use 'modal-lg' or 'modal-sm' if desired)
extraDlgClass: $scope.extraDlgClass,
width: $scope.width,
height: $scope.height,
maxWidth: $scope.maxWidth,
maxHeight: $scope.maxHeight,
minWidth: $scope.minWidth,
minHeight: $scope.minHeight
});
$scope.modalInstance.result.then(function ()
{
console.log('Modal closed at: ' + new Date());
},
function ()
{
console.log('Modal dismissed at: ' + new Date());
});
};
$scope.ok = function ($event)
{
if ($event)
$event.preventDefault();
$scope.modalInstance.close("OK");
};
$scope.cancel = function ($event)
{
if ($event)
$event.preventDefault();
$scope.modalInstance.dismiss('cancel');
};
$scope.openFlexModal = function ()
{
$scope.open();
}
}]);
</script>
添加一个“打开”按钮,然后开火。
<button ng-controller="myTest" class="btn btn-default" type="button" ng-click="openFlexModal();">Open Flex Modal!</button>
现在,您可以添加所需的任何其他类,或仅根据需要更改宽度/高度大小。
我进一步将其包含在包装指令中,从现在开始,这应该是微不足道的。
干杯。
您可以使用角度模态的size属性以非常简单的方式执行此操作。
var modal = $modal.open({
templateUrl: "/partials/welcome",
controller: "welcomeCtrl",
backdrop: "static",
scope: $scope,
size:'lg' // you can try different width like 'sm', 'md'
});
如果您只想使用默认的大尺寸,可以添加'modal-lg':
var modal = $modal.open({
templateUrl: "/partials/welcome",
controller: "welcomeCtrl",
backdrop: "static",
scope: $scope,
windowClass: 'modal-lg'
});
对模态对话框使用最大宽度为角度5
.mod-class .modal-dialog {
max-width: 1000px;
}
并按照其他建议使用windowClass,例如:
this.modalService.open(content, { windowClass: 'mod-class' }).result.then(
(result) => {
// this.closeResult = `Closed with: ${result}`;
}, (reason) => {
// this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
另外,我不得不将css代码放入全局样式> styles.css中。