我已成功打开MatDialog,但内容为空。我将我想要的内容显示在./game-window-dialog.html文件中。这是正确的地方吗?这是我的第一个StackOverflow问题,所以如果我做错了什么,请善待。提前谢谢!
@Component({
selector: 'ngdw-game-window',
templateUrl: './game-window.component.html',
styleUrls: ['./game-window.component.css']
})
export class GameWindowComponent implements OnInit {
newgame: Game;
constructor(private gameService: GameService, public dialog: MatDialog) { }
ngOnInit() {
this.getGame();
}
getGame(): void {
this.newgame = this.gameService.gameInit();
}
openDialog() {
const dialogRef = this.dialog.open(GameWindowDialogComponent, {
height: '350px'
});
}
}
@Component({
selector: 'ngdw-game-window-dialog-component',
templateUrl: './game-window-dialog.html'
})
export class GameWindowDialogComponent {
constructor(
public dialogRef: MatDialogRef<GameWindowDialogComponent>) { }
onExitClick(): void {
this.dialogRef.close();
}
}
答案 0 :(得分:1)
您已将其放在正确的位置。对话框无法呈现的原因是:
GameWindowDialogComponent
中声明entryComponents
:https://angular.io/api/core/NgModule#entryComponents GameWindowDialogComponent
:https://angular.io/api/core/NgModule#declarations 您需要同时执行这两项操作才能使其正常工作。检查这两个地方。
另外,我建议将其重命名为game-window-dialog.component.html
。