【发布时间】:2019-01-19 11:28:25
【问题描述】:
我正在使用在 ap-fullcalendar 上单击事件时执行的 mat 对话框。我正在使用 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');
});
}
}
我的主要组件 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>
【问题讨论】:
-
这个运气好吗?
标签: angular dialog fullcalendar angular-material angular6