簡體   English   中英

如何在 Angular 中使用 Nativescript 關閉模態窗口?

[英]How to close a modal window with Nativescript in Angular?

我有一個使用模態服務的模態:

import { ModalDialogService } from "nativescript-angular/directives/dialogs";    
private modal: ModalDialogService,

例如,我可以調用模態

  this.modal.showModal(MyModalComponent, options).then(res => {
      // console.log(res);
  }); 

現在我想關閉模態,但不是從模態本身內關閉。 這已經適用於 iOS:

        const page = topmost().currentPage;
        if (page && page.modal) {
          page.modal.closeModal();
        } else {
          console.log("error closing modal!!!!");
        }

但是在Android上運行它,它總是會轉到錯誤console.log,導致模態沒有被關閉。 用戶仍然可以關閉它(模態有一個關閉按鈕),但我也想以編程方式關閉模態。

那不是您應該如何在Angular中做到的方式。 注入ModalDialogParams並使用closeCallback方法。

constructor(private modalDialogParams: ModalDialogParams) {}

onCloseButtonTap() {
    this.modalDialogParams.closeCallback();
}

我有一個類似的問題,我最終做的是實現一個接口來激活其他類的模態參數上的 closeCallback 。 這是一個展示我所做的操場https://play.nativescript.org/?template=play-ng&id=q1mDZI&v=6

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM