gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 23:13:10 25 4
gpt4 key购买 nike

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

当我单击一个事件时,会出现以下对话框,但没有任何信息。

Dialog with no info

按下“购买”按钮后,它会将我带到实际的对话框。

Dialog with full info

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

任何帮助表示赞赏!

我的主要组件 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');
});
}
}

我的主要组件 HTML
<div *ngIf="calendarOptions">
<angular2-fullcalendar #ucCalendar [options]="calendarOptions" (eventDrop)="updateEvent($event.detail)"
(eventResize)="updateEvent($event.detail)">
</angular2-fullcalendar>
</div>

我的对话组件 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();
}
}

我的对话框组件 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>

最佳答案

我遇到了一个与此非常相似的问题。我在网上搜索并试图查看是否有任何解决方法的线索,因为您似乎没有想出答案。

我能够让问题自行修复,但我不确定到底是什么原因造成的。我所做的是一个 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: {}
});
...
});`

关于angular - 在 fullcalendar 中使用的 mat 对话框打开两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51810372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com