Joan Nadal Brotat
Joan Nadal Brotat

Reputation: 122

Close Angular md-dialog from an iframe

I am looking to see if it's possible to close a md-dialog (Angular Material) from an iframe, that iframe contains an other Angular App. The iframe is loaded into the md-dialog that I would like to close.

See an example:

<md-dialog class="modal-dialog contract-detail">
    <md-dialog-content flex="auto">
        <div class="modal-header">
            <button type="button" class="close" aria-label="Close" ng-click="closeDialog()">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="modal-body">
      <iframe ng-src="{{urlIframe}}"
              frameborder="0"
              allowfullscreen
              style="position: absolute;top: 0;left: 0;width: 100%;height: 90%;"
              align="center">
      </iframe>
    </div>
  </md-dialog-content>
</md-dialog>

The var {{urlIframe}} contains the Angular app URL.

Upvotes: 0

Views: 1425

Answers (1)

Thaadikkaaran
Thaadikkaaran

Reputation: 5226

You can access parent angular application's scope like,

var $scope = parent.angular.element('.modal-dialog.contract-detail').scope();

And then just calling the closeDialog function on $scope, would close the dialog.

Upvotes: 1

Related Questions