我的 Kalender 有问题。我想在其中加载一些事件,但我总是必须先点击它。这里有些例子:
(蓝点是事件数组的事件)
我的代码来填充事件数组:
initMethod() {
return this.service
.getEmployees()
.pipe(tap(
(listBooks) => {
this.books = listBooks;
this.events = this.books.map((book) => {
return {
start: new Date(book.date_from_og),
end: new Date(book.date_to_og),
type: ""+book.type,
title: "" + book.device + "",
color: colors.blue,
actions: this.actions,
resizable: {
beforeStart: false,
afterEnd: false
},
draggable: false
}
});
}))
}
我的 ngOnInit:
ngOnInit() {
this.initMethod().subscribe(() => {
if(this.events[0].start == this.books[0].date_from_og) {
this.dialog.closeAll();
}
});
}
我的构造函数:
constructor(private modal: NgbModal, private service: BookingService, private dialog: MatDialog) {
this.dialog.open(DialogLaedt, {
width: '650px'
});
}
我已经用 Dialog 尝试过它,它会一直显示到数据加载完毕,但这并没有奏效。
这取决于您用于日历的库,但可能在角度区域之外发生了某些事情,或者您的更改检测策略设置为OnPush
. 所以你需要告诉 angular 有些东西已经改变了,它需要刷新视图。为此,您可以使用ChangeDetectorRef
constructor(private modal: NgbModal, private service: BookingService,
private dialog: MatDialog, private cdr: ChangeDetectorRef) {
//...
ngOnInit() {
this.initMethod().subscribe(() => {
//...
this.cdr.detectChanges();//Tell angular that something has changed
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句