2017-10-19 42 views
0

我在查看是否可以從iframe關閉md對話框(Angular Material),該iframe包含其他Angular App。 iframe被加載到我想要關閉的md對話框中。關閉iframe中的角度md對話框

參見一個例子:

<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> 

的變種{{urlIframe}}包含角應用URL。

+0

'urlIframe'是否意識到它在iframe中?你可以以某種方式提供一個回調的iframe?此外,你似乎錯過了代碼中的一些結束標籤。 – bracco23

+0

對不起,我似乎在創建帖子時出現了「代碼」按鈕錯誤。現在已經修復了。我需要從iframe url應用程序進行回調。或者我需要關閉加載到iframe中的應用程序的md對話框。我嘗試過'window.parent.close()',但它不起作用。謝謝 –

回答

1

您可以訪問父角應用程序的範圍一樣,

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

然後就是呼籲$scopecloseDialog功能,將關閉對話框。

+0

完美!這對我很有用,非常感謝! –