在fullcalendar中使用的mat对话框打开两次

Idr*_*.AH 1 dialog fullcalendar angular-material angular angular6

我正在使用mat对话框,该对话框在ap-fullcalendar上单击事件时执行.我正在使用Angular6.

单击某个事件时,会出现以下对话框,没有任何信息.

对话没有信息

一旦我按下"购买"按钮,它就会转到实际的对话框.

带有完整信息的对话框

注意:按钮似乎没有按预期工作,但是,我认为这取决于我原来的问题.此外,当我双击我的事件时,我会在第一个屏幕截图所示的对话框打开时获得不同的行为.当我按或取消时,它会关闭.

任何帮助表示赞赏!

我的主要组成部分TS:

import { Component, OnInit, ViewChild, Inject } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { CalendarComponent } from 'ap-angular2-fullcalendar/src/calendar/calendar';
import { CalendarService } from '../_services/calendar.service';
import { DialogComponentComponent } from './dialog-component/dialog-component.component';

export interface DialogData {
  animal: string;
  name: string;
}

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent{

  calendarOptions: any;
  displayEvent: any;
  @ViewChild(CalendarComponent) ucCalendar: CalendarComponent;
  animal: string;
  name: string;
  subjectFilter: string;

  constructor(protected calendarService: CalendarService, private dialog: MatDialog) { }

  ngOnInit(){
    this.calendarService.getEvents(this.subjectFilter).subscribe(data => {
      console.log(data);
      this.calendarOptions = {
        editable: true,
        eventLimit: false,
        header: {
          left: 'prev,next today',
          center: 'title',
          right: 'month,agendaWeek,agendaDay,listMonth'
        },
        events: data,
        eventClick: (calEvent, jsEvent, view) => {
          this.openDialog(calEvent);

          console.log('Event: ' + calEvent.title);
          console.log('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY);
          console.log('View: ' + view.name);
        },
      };
    });
  }

  openDialog(calEvent): void {
    console.log("opendialog");
    const dialogRef = this.dialog.open(DialogComponentComponent, {
      data : {
        title: calEvent.title,
        start: calEvent.start,
        end: calEvent.end,
        price: calEvent.price
      }
    });

    dialogRef.afterClosed().subscribe(result => {
      console.log('The dialog was closed');
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

我的主要组件HTML

<div *ngIf="calendarOptions">
  <angular2-fullcalendar #ucCalendar [options]="calendarOptions" (eventDrop)="updateEvent($event.detail)"
              (eventResize)="updateEvent($event.detail)">
  </angular2-fullcalendar>
</div>
Run Code Online (Sandbox Code Playgroud)

我的对话框组件TS:

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

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

  constructor(
    public dialogRef: MatDialogRef<DialogComponentComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) {console.log("constructor");}

  onNoClick(): void {
    this.dialogRef.close();
  }
}
Run Code Online (Sandbox Code Playgroud)

我的对话框组件HTML:

<h2 mat-dialog-title>{{data.title}}</h2>

<mat-dialog-content>
  <p>Lesson Details:</p>
  <p>Start - {{data.start}}</p>
  <p>End - {{data.end}}</p>
  <p>Price - {{data.price}}</p>
</mat-dialog-content>

<mat-dialog-actions>
  <button mat-raised-button mat-button>Cancel</button>

  <button mat-raised-button (click)="onNoClick()">Buy</button>
</mat-dialog-actions>
Run Code Online (Sandbox Code Playgroud)

小智 5

我遇到了一个非常类似的问题.我正在网上搜索并试图查看是否有任何修复的线索,因为它看起来不像你想出了答案.

我能够解决问题,但我不确定究竟是做了什么.我做的是一个npm update然后删除node_modules文件夹并运行一个新的npm install

接下来,我遇到了一些其他问题,其中一些人遇到了类似的问题.看起来你可以通过window调用弹出对话框来轻松解决问题.事实证明,一些问题是对话框出现在NgZone之外,所以要修复,import {NgZone} from '@angular/core'在构造函数中包含它constructor(private dialog: MatDialog, readonly ngZone: NgZone)然后在打开对话框时使用它

this.ngZone.run(() => {
 const ref = this.dialog.open(DialogComponent, {
  options..,
  data: {}
 });
 ...
});`
Run Code Online (Sandbox Code Playgroud)

  • 同样的事情,当我尝试在全局错误处理程序上打开一个对话框时(提供重新加载窗口和其他选项,以及错误消息和报告发送)。使用 `ngZone.run()` 解决了它! (3认同)