微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular – MatDialog无法正确显示

我正在尝试使用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?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐