gpt4 book ai didi

angular - MatDialog 显示不正确

转载 作者:太空狗 更新时间:2023-10-29 17:04:06 31 4
gpt4 key购买 nike

我正在尝试使用 MatDialog 并基于 this example我已经按如下方式实现了该对话框:

import {Component, Inject, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {AuthenticationService} from '../../../service/authentication.service';
import {MAT_DIALOG_DATA, MatDialog, MatDialogRef} from '@angular/material';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent {

constructor(private router: Router, public dialog: MatDialog) { }

openDialog(): void {
const dialogRef = this.dialog.open(CreateGroupDialogComponent);
}
}

@Component({
selector: 'app-create-group-dialog',
template: `
<span>Hello World!</span>
`
})
export class CreateGroupDialogComponent {
constructor(public dialogRef: MatDialogRef<CreateGroupDialogComponent>) { }
}

但是,即使在我按下相应按钮时出现对话框,我得到的结果是:

enter image description here

HTML 模板未显示,模态框的尺寸错误。

我不明白问题是什么。为什么模态没有正确绘制?

这是打开模式时生成的 HTML 代码。可以看出它是空的。

enter image description here

最佳答案

你需要将它添加到 @NgModule 上的 entryComponents

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { MatDialogModule, MatButtonModule } from '@angular/material';

import { AppRoutingModule } from './app-routing.module';

import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
import { HomeComponent, DialogOverviewExampleDialogComponent } from './home/home.component';


@NgModule({
declarations: [
AppComponent,
LoginComponent,
HomeComponent,
DialogOverviewExampleDialogComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
MatDialogModule,
MatButtonModule
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [
DialogOverviewExampleDialogComponent
]
})
export class AppModule { }

复制 Angular2 material dialog has issues - Did you add it to @NgModule.entryComponents?

关于angular - MatDialog 显示不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47240838/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com