Miguel Frias
Miguel Frias

Reputation: 2710

Angular Material Dialog modal error

this is the first time working with angular 4 and material design, im trying to create a modal window with angular material design and have this two files:

roomlist.component

import { Component, OnInit, Inject } from '@angular/core';
import { RoomService } from '../../services/room.service';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { RoomDialogComponent } from './dialogs/roomDialogs/room.dialog';


@Component({
  selector: 'app-roomlist',
  templateUrl: './roomlist.component.html',
  styleUrls: ['./roomlist.component.css']
})
export class RoomlistComponent implements OnInit {
  public rooms: any;
  public roomsFilter = {
    date: new Date,
    aviable: 'all',
    globalSeach: ''
  };
  constructor(public roomService: RoomService, public dialog: MatDialog) {
  }

  ngOnInit() {
    this.getData();
  }

  public getData(): any {
    console.log(this.roomsFilter.date);
    this.roomService.getRooms({ date: 'now' })
      .then((res) => {
        this.rooms = res;
        console.log(this.rooms);
      });
  }

  public openDialog(event, room): void {
    const dialogRef = this.dialog.open(RoomDialogComponent, {
      width: '250px',
      data: room
    });

    dialogRef.afterClosed().subscribe(result => {
      console.log(result);
    });
  }

}

and this one: room.dialog

import { Component, Inject } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';

/**
 * @title Dialog Overview
 */

@Component({
  selector: 'app-room-dialog',
  templateUrl: './room.dialog.html',
})
export class RoomDialogComponent {

  constructor(
    public dialogRef: MatDialogRef<RoomDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any) { }

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

}

the modal should open when i press a button that is trigger the function openDIalog but im geting this error message No component factory found for RoomDialogComponent. Did you add it to @NgModule.entryComponents?

any idea

Upvotes: 1

Views: 4879

Answers (1)

Carsten
Carsten

Reputation: 4208

Did you do what the error said?

Did you add it to entry components????

@NgModule({
entryComponents: [
    YourDialogComponent
  ]
})

Upvotes: 4

Related Questions