Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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>) {  }
}@H_197_8@ 
 

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

angular – MatDialog无法正确显示

不显示HTML模板,并且模式的尺寸错误.

我不知道问题是什么.为什么模态没有正确绘制?

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

angular – MatDialog无法正确显示

解决方法

@H_618_24@ 您需要将它添加到@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 { }@H_197_8@ 
 

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

大佬总结

以上是大佬教程为你收集整理的angular – MatDialog无法正确显示全部内容,希望文章能够帮你解决angular – MatDialog无法正确显示所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。