【发布时间】:2015-07-07 10:09:17
【问题描述】:
我正在尝试学习在 AngularJS 中单击按钮时打开模式对话框,但无法这样做。我检查了 chrome 控制台,但没有错误。另外,由于我正在学习AngularJS,请建议当chrome控制台没有显示任何错误时该怎么做。
这是我的代码
<html ng-app="MyApp">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.min.css" />
<script type="text/javascript">
var myApp = angular.module("MyApp", []);
myApp.controller('MyController', function ($scope) {
$scope.open = function () {
$scope.showModal = true;
};
$scope.ok = function () {
$scope.showModal = false;
};
$scope.cancel = function () {
$scope.showModal = false;
};
});
</script>
</head>
<body ng-controller="MyController">
<button class="btn btn-primary" ng-click="open()">Test Modal</button>
<!-- Confirmation Dialog -->
<div class="modal" modal="showModal" close="cancel()">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Delete confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" ng-click="cancel()">No</button>
<button type="button" class="btn btn-primary" ng-click="ok()">Yes</button>
</div>
</div>
</div>
</div>
<!-- End of Confirmation Dialog -->
</body>
</html>
【问题讨论】:
-
因为您使用的是 Angular 和 Bootstrap,所以我会在这里使用模态形式:angular-ui.github.io/bootstrap
-
这里你有一个简单的example 如何使用 angularjs 的模态
标签: angularjs