调用$ mdDialog(Angular Material)确认而不是默认Javascript

时间:2016-03-29 03:41:01

标签: javascript angularjs dialog material-design angular-material

脚本

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();
        });
    };

1 个答案:

答案 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';
});