Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular material close mdDialog from template directive

I'm tring to close dialog by this manner :

showAlert(ev) {
    this.mdDialog.show({
      restrict: 'E',
      template:'<loader></loader>' +
      '    <md-button ng-click="this.mdDialog.hide()" class="md-primary">' +
    '      Close Dialog' +
    '    </md-button>' ,
      parent: angular.element(document.body.childNodes[5]),
      clickOutsideToClose:true
  });
};
closeDialog() {
  this.mdDialog.hide();
};

but the button appears and do nothing. Any idea ?

like image 655
Harel.Lebel Avatar asked Oct 18 '22 02:10

Harel.Lebel


2 Answers

I found the answer there http://webiks.com/mddialog-with-a-confirmation-dialog/ ,

in the last plunker in page https://embed.plnkr.co/HiLJlsp0yfcukxi2McNZ/ .

the scope property was not needed.

P.S

Now I see @camden_kid answer after edition was, correct for me as well, thanks.

like image 89
Harel.Lebel Avatar answered Nov 11 '22 11:11

Harel.Lebel


Here you go - CodePen

Markup

<div ng-controller="MyController as vm" class="md-padding" ng-cloak="" ng-app="app">
   <md-button class="md-primary md-raised" ng-click="vm.show($event)">Open</md-button>
  </script>
</div>

JS

angular.module('app',['ngMaterial'])

.controller('MyController', function($scope, $mdDialog) {
  this.show = function(ev) {
    $mdDialog.show({
      restrict: 'E',
      template:'<loader></loader>' +
      '    <md-button ng-click="vm.hide()" class="md-primary">' +
    '      Close Dialog' +
    '    </md-button>' ,
      parent: angular.element(document.body),
      clickOutsideToClose:true,
      targetEvent: ev,
      controller: DialogController,
      controllerAs: "vm"
    });
  };
});

function DialogController($scope, $mdDialog) {
  this.hide = function() {
    $mdDialog.hide();
  };
}
like image 42
camden_kid Avatar answered Nov 11 '22 12:11

camden_kid