Kerim Çevik
Kerim Çevik

Reputation: 67

Angular material dialog is hidden

I have implemented the Angular material dialog into my application. However the dialog is not showing up, instead it is hidden beneath my component. To make this issue a bit clear i added some images.

Dialog components with my main component showing

Dialog components with my main component hidden

So my question is how can I put my dialog on top of my view?

UPDATE:

I have no console errors and I followed the tutorial on the material website Angular Material Dialog. So no extra css or anything just the following components and code:

My main component which opens the dialog (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}
    });
  }


}

The dialog component(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();
  }
}

Upvotes: 1

Views: 3360

Answers (1)

Rager
Rager

Reputation: 876

This happens when you don't provide any Angular Material styles. I recommend importing one into your styles.css file.

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

Or you could create your own styles.

Upvotes: 1

Related Questions