脚本
if (true) {
if(!confirm("Are you sure ?"))
{
event.preventDefault();
}
}
如何调用Angular Material对话框而不是默认的javascript确认?像
这样的东西function(event) {
var confirm = $mdDialog.confirm()
.title('Are you sure ?')
.targetEvent(event)
.ok('ok')
.cancel('cancel');
$mdDialog.show(!confirm).then(function() {
event.preventDefault();
});
};
答案 0 :(得分:1)
检查这支笔。只需在$event
中传递ng-click
并使用素材库提供的$mdDialog
服务即可打开提醒对话框。
http://codepen.io/next1/pen/KzvwXq
HTMLFILE
<md-button class="md-primary md-raised" ng-click="showConfirm($event)">
Confirm Dialog
</md-button>
JS档案
$scope.showConfirm = function(ev) {
var confirm = $mdDialog.confirm()
.title('Are you sure?')
.textContent('Are you really sure?')
.ariaLabel('Lucky day')
.targetEvent(ev)
.ok('Yes')
.cancel('No');
$mdDialog.show(confirm).then(function() {
$scope.status = 'Yes';
}, function() {
$scope.status = 'No';
});