in my application I have a Dashboard where the user can add and delete widgets. To do so I am using angular-gridster2. This works well, but when I am adding or deleting a widget from the dashboard first no widgets are displayed anymore and then only after a refresh the correct changes occur. My Widget list the ngFor directive is iterating through is build from an observable. These values change correctly.
This is my html:
<gridster #dashboardgrid [options]="options" class="widget-container">
<gridster-item *ngFor="let widget of widgetList()" (mouseup)="setCurrentWidgetId(widget.id)" [item]="widget.position" class="gridster-design drag-handler">
<!-- some stuff-->
</gridster-item>
</gridster>
In my ngOnInit
I am subscribing from the observable:
this.dataService.currentDashboardId.subscribe(dashboardId => this.currentDashboardId = dashboardId);
this.dataService.currentSheetId.subscribe(sheetId => this.currentSheetId = sheetId);
this.dataService.projectData
.subscribe((project: Project) => {
this.project = project;
});
And this is the method returning the list of widgets
which should be displayed:
widgetList(): Array<Widget> {
return this.project.dashboards
.find(x => x.id === this.currentDashboardId).sheets
.find(x => x.id === this.currentSheetId).widgets;
}
I really can't find the reason for this behaviour so if anybody does I appreciate that. Thanks in advance.