【问题标题】:Cannot display Angular dialog properly无法正确显示 Angular 对话框
【发布时间】:2020-08-25 03:40:24
【问题描述】:

我正在尝试在 Angular 中创建一个对话框,但该对话框未显示在中心,仅显示为左侧的垂直白色矩形。 我将附上一张描述确切问题的图片:screenshot of the page

  1. 我的appmodule.ts文件中包含了入口组件
  2. 编译时没有错误。

标题component.ts文件:

import { Component, OnInit } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material';
import { LoginComponent } from '../login/login.component';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss']
})

export class HeaderComponent implements OnInit {

  constructor(public dialog: MatDialog ) { }

  ngOnInit() {
  }

 openLoginForm() {
    this.dialog.open(LoginComponent, {width: '500px', height: '450px'});
  }
}

【问题讨论】:

  • 您是否在项目中添加了@angular/material 样式?
  • 你能详细点吗,我没听懂
  • 我在 @Santosh 的回答中的 cmets 中看到您已经添加了样式。如果这是您要添加材料的项目,我建议您使用ng add @angular/material。它会执行@angular/material 入门指南中描述的所有步骤,将其添加到您的项目中。如果这是一个 Ivy 项目,则在 NgModule 定义中不需要任何 entryComponents

标签: javascript node.js angularjs reactjs


【解决方案1】:

entrycomponents数组中添加LoginComponentmodule

像这样。

entryComponents: [LoginComponent]

【讨论】:

  • 我已经在入口组件中包含了 LoginComponent
  • 编译成功,没有任何错误** Angular Live Development Server 正在监听 localhost:4200,在localhost:4200 上打开浏览器**:编译成功。
  • 你有没有导入material css如果没有把它放到全局css中style.css@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';
  • 我也在全局styles.css文件中导入了这个
猜你喜欢
  • 2017-08-14
  • 2017-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-17
  • 2017-10-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多