2016-10-04 110 views
0

這是非常複雜添加這個新的對話框,這是我不能夠添加自己的唯一部件。使用對話是非常複雜的

  1. 我不知道如果我需要的東西添加到我的app.module.ts
  2. 如何創建這個對話框?我真的不明白有很多信息Dialogreference

我需要設置一次嗎?在我的根組件或什麼?因爲它不起作用,我可以將它添加到我的構造函數中,一旦我有「沒有提供者MdlDialogReference」一旦我有「沒有所有參數(?)」。

實際代碼:

FILE app.component.ts

constructor(private vcRef: ViewContainerRef, 
       private dialog: MdlDialogReference, private dialogService: MdlDialogService, private httpService: HttpService, private communicationInsideServices : CommunicationInsideServices, private activatedRoute : ActivatedRoute, private router : Router) { 

    } 

    get viewContainerRef() { 
    return this.vcRef; 
    } 

有沒有錯誤?因爲這不會加載我的應用程序,我怎樣才能將這個對話框調入另一個子組件?

+0

你爲什麼要添加MdlDialogReference的依賴?你想把你的appcomonent作爲dialogcontent嗎? – michael

+0

非常感謝,我不知道是什麼MdDialogReference,不,我不想要的應用程序組件作爲我dialogcontent,我需要的東西導入到我app.mobule.ts那裏是我的引導ngModule得到這個對話框的作品?因爲它不會工作或我使用的是錯誤的話,如果你有一個明確plunkr演示,這是值得歡迎的 – istiti

+0

清潔我的所有代碼和中庸之道添加到我的成分在我的構造函數: '構造函數(私人dialogService:MdlDialogService )' 和ngAfterViewInit '讓結果= this.dialogService.alert( '這是一個簡單警報'); result.then(()=> console.log('alert closed'));' 我得到這個錯誤 'TypeError:無法讀取未定義的'parentInjector'屬性 – istiti

回答

0

你是接近的解決方案!指定對話框連接到的ViewContainerRef非常重要。請看看在app.component.ts這個工作plnkr(http://plnkr.co/edit/HgAvCnzkWAmK1NVxfEUM?p=preview):

constructor(private dialogService: MdlDialogService, 
    private viewContainerRef: ViewContainerRef){ 
    dialogService.setDefaultViewContainerRef(viewContainerRef); 
} 

這隻需要做一次。可以爲每個showCustomDialog調用提供viewConatinerRef,但在根應用程序的構造器中執行一次更容易。應該有一條錯誤消息通知您有關缺少的信息(將在即將發佈的版本中修復)。

版本2.0.0更新: 您不再需要手動撥打setDefaultViewContainerRef。就在dialog-outlet元素添加到您的HTML文件: 這樣:

<html> 
    <head>...</head> 
    <body> 
    <app-root>...</app-root> 
    <dialog-outlet></dialog-outlet> 
    </body> 
</html>