[英]AngularJS ui.bootstrap modal dialog is not showing
I have already seen this question: AngularJS bootstrap.ui modal not showing . 我已经看到了这个问题: AngularJS bootstrap.ui模态未显示 。 But any of those answers didn't help me.
但是这些答案都对我没有帮助。
I'm trying to display modal dialog using ui.bootstrap
module. 我正在尝试使用
ui.bootstrap
模块显示模式对话框。 This is my index.html page 这是我的index.html页面
<!doctype html>
<html lang="en" ng-app="app">
<head>
<title>Title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">
</head>
<body ng-controller="Controller">
<button type="button" class="btn btn-info" ng-click="open()">Open</button>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js" integrity="sha384-o+RDsa0aLu++PJvFqy8fFScvbHFLtbvScb8AjopnFD+iEQ7wo/CG0xlczd+2O/em" crossorigin="anonymous"></script>
<script src="lib/angular.js"></script>
<script src="lib/ui-bootstrap-tpls.js"></script>
<script>
angular
.module("app", ["ui.bootstrap"])
.controller("Controller", function ($scope, $uibModal) {
$scope.open = function () {
$uibModal.open({
ariaLabelledBy: 'modal-title',
ariaDescribedBy: 'modal-body',
templateUrl: 'modal.template.html',
controller: 'ModalController',
resolve: {
users: function () {
return [
{ id: 1, name: "aaa" },
{ id: 2, name: "bbb" },
{ id: 3, name: "ccc" }
];
}
}
}).result.then(
function (result) {
console.log(result);
},
function () {
console.log("Modal dialog dismissed!");
}
);
}
})
.controller("ModalController", function ($scope, $uibModalInstance) {
$scope.ok = function () {
$uibModalInstance.close("Modal dialog successfully closed!");
}
$scope.cancel = function () {
$uibModalInstance.dismiss("cancel");
}
});
</script>
</body>
</html>
modal.template.html modal.template.html
<div class="modal-header">
<h3 class="modal-title" id="modal-title">Modal Title</h3>
</div>
<div class="modal-body" id="modal-body">
<ul>
<li ng-repeat="user in users">{{user}}</li>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" ng-click="ok()">Ok</button>
<button type="button" class="btn btn-light" ng-click="cancel()">Cancel</button>
</div>
I don't see any errors in the console, but the modal dialog is not showing. 我在控制台中没有看到任何错误,但是没有显示模式对话框。
There are some issues in your code: 您的代码中存在一些问题:
<script>
tags into head
section. <script>
标记移至head
。 ui-bootstrap-tpl
is compatible with bootstrap 3, so use v3.3.7 ui-bootstrap-tpl
与bootstrap 3兼容,因此请使用v3.3.7 If you resolve something, it means that you can access it in your controller, but it's not assigned to $scope
. 如果您解决了某些问题,则意味着您可以在控制器中访问它,但未将其分配给
$scope
。 So inject users
into your controller and assign its value. 因此,将
users
注入您的控制器并分配其值。
.controller("Controller", function ($scope, $uibModal, users) { $scope.users = users; /* rest of code*/ }
You can see result of these changes in this plunker 您可以在此扬声器中看到这些更改的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.