3
this.$mdDialog.show({
    controllerAs: 'ctrl',
    resolve: {
        product: product
    },
    controller:($mdDialog, product) => {
       close() => {
           $mdDialog.hide({productToUpdate: product}
       }
    },
    templateUrl: 'product-dialog.tmpl.html',
    parent: angular.element(document.body),
       clickOutsideToClose: true,
    }).then(productToUpdateOrDelete => { // on hide
       cb(productToUpdateOrDelete);
    }, () => { // on clickoutside or escape
       // Need to run my cb() here with the modified product
    });
}

I need to pass an object when $mdDialog is closed by escape and clickOutside.

Can't find anything about it in the docs. https://material.angularjs.org/latest/api/service/$mdDialog

Isn't it possible?

The.Bear
  • 5,621
  • 2
  • 27
  • 33
Joe
  • 4,274
  • 32
  • 95
  • 175

1 Answers1

3

There is no way to interact with those events, check: No way to intercept MdDialog close events #3893

My recomendation would be to do what @camden_kid suggested in this comment

  1. Create a service
  2. Call that service on the onRemoving function
  3. Save what ever object you need to in that service.
  4. In the cancellation of the $mdDialog.show promise callback, call the service to obtain the value.

Check codepen as example

Other option would be to use preserveScope: true and modify the parent's scope directly and recover the value once the dialog is cancelled.