隐藏角度材质对话框

时间:2018-01-16 13:16:28

标签: angular dialog angular-material2

我已将Angular材质对话框实现到我的应用程序中。但是,对话框没有显示,而是隐藏在我的组件下面。为了使这个问题有点清楚,我添加了一些图像。

Dialog components with my main component showing

Dialog components with my main component hidden

所以我的问题是如何将我的对话框置于我的视线之上?

更新:

我没有控制台错误,我按照资料网站Angular Material Dialog上的教程进行操作。所以没有额外的css或任何东西只是以下组件和代码:

我的主要组件打开对话框(EditComponent)

import { Component, OnInit, ViewEncapsulation, Inject } from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
import { Result } from '../Types/result';
import { ResultService } from '../result.service';
import { LanguageService } from '../language.service';
import { Router } from '@angular/router';
import { Process } from '../Types/process';
import { onLoadDown, onLoadAppear } from '../animations';
import { EditDialogComponent } from '../edit-dialog/edit-dialog.component';

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.css'],
  animations: [onLoadDown, onLoadAppear],
  encapsulation: ViewEncapsulation.None
})
export class EditComponent implements OnInit {
  results: Result[] = new Array();

  constructor(private resultService: ResultService, private languageService: LanguageService,
    private router: Router, public dialog: MatDialog) { }

  ngOnInit() {
    this.results = this.resultService.getResults();
    console.log(this.results);
  }

  openDialog(editResult: Result): void {
    const dialogRef = this.dialog.open(EditDialogComponent, {
      width: '250px',
      data: { result: editResult}
    });
  }


}

对话框组件(EditDialogComponent)

import { Component, OnInit, Inject, ViewEncapsulation } from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
import { ResultService } from '../result.service';
import { Router } from '@angular/router';
import { LanguageService } from '../language.service';

@Component({
  selector: 'app-edit-dialog',
  templateUrl: './edit-dialog.component.html',
  styleUrls: ['./edit-dialog.component.css'],
  encapsulation: ViewEncapsulation.None
})
export class EditDialogComponent {

  constructor(
    public dialogRef: MatDialogRef<EditDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any, private resultService: ResultService,
    private router: Router, private languageService: LanguageService) {
     }

  onNoClick(): void {
    this.dialogRef.close();
  }
}

1 个答案:

答案 0 :(得分:0)

当您不提供任何Angular Material样式时,就会发生这种情况。我建议将一个导入您的styles.css文件。

@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';

或者您可以创建自己的样式。