2017-03-05 47 views
0

親愛的#1社區,角2對話框那倒開放

我與angular2對話的問題,befor我給你在這裏的錯誤是我的代碼的snipet(我有exluced了很多,但我認爲他們可能不會在這裏很重要)

signup.component.ts文件:

import {Component, OnInit, NgZone, SimpleChanges} from '@angular/core'; 
import {MdDialog} from '@angular/material'; 

import template from './signup.component.html'; 

@Component({ 
    selector: 'signup', 
    template 
}) 
export class SignupComponent implements OnInit { 

    constructor(private router: Router, private zone: NgZone, private formBuilder: FormBuilder, public dialog: MdDialog) { 
    } 
openDialog() { 
     this.dialog.open(DialogOverviewExampleDialog); 
    } 
@Component({ 
    selector: 'dialog-overview-example-dialog', 
    templateUrl: './dialog.html', 
}) 
export class DialogOverviewExampleDialog {} 

signup.component.html文件:

<h3 flex>Just<a (click)="openDialog()">Click here</a></h3> 

和dialog.html:

<p>pls work</p> 

我得到的控制檯上的錯誤在Chrome: 無元件廠發現DialogOverviewExampleDialog

回答

1

DialogOverviewExampleDialog成分必須在NgModule的entryComponents領域中聲明。否則,角度編譯器不知道這個組件顯示在某處(因爲它的選擇器不在任何模板中使用),所以它不會被編譯。

+0

這可能是我再次愚蠢,但我在哪裏可以找到entryComponents? –

+0

傳遞給'@NgModule()'的對象。這通常在app.module.ts文件中。 –

+0

非常感謝老兄:它工作。我太高興了 –