我正試圖學習在AngularJS中單擊按鈕時打開模式對話框,但無法這樣做。我檢查了Chrome控制檯,但沒有錯誤。此外,由於我正在學習AngularJS,因此請在Chrome控制檯沒有顯示任何錯誤時提出建議。AngularJS按鈕單擊打開模式
這裏是我的代碼
<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>
,因爲你正在使用角度和引導我將在這裏使用的模態形式:http://angular-ui.github.io/bootstrap/ – Jax
在這裏,你有一個簡單的[示例](http://jsfiddle.net/dwmkerr/8MVLJ/)如何使用modal with angularjs –