I am receiving the following error:
"Expression has changed after it was checked. Previous value: 'null: 0'. Current value: 'null: 4'."
When I moved the line 'this.ondetails.emit(this.items.length);' to the constructor it did not provide me with an initial value so I had to move it to the ngOnInit().
ngOnInit() {
this.ondetails.emit(this.items.length);
}
This gives me the initial values I need and the application works well but when I do this, I receive the error.
notifications-widget.component.ts
export class NotificationsWidgetComponent implements OnInit, AfterViewInit {
@Input() config: NotificationsConfigComponent;
@Output() ondetails = new EventEmitter();
public items = [
{
title: 'Import of .......... failed',
description:
'Lorem ipsum dolor sit amet',
read: true
},
{
title: 'Manager ..........approved the budget',
description:
'Lorem ipsum dolor sit amet',
read: true
}
];
constructor() {
}
deleteWidget(i) {
this.items.splice(i, 1);
this.ondetails.emit(this.items.length);
}
itemRead(i) {
if (this.items[i].read == false) {
this.items[i].read = true;
}
}
ngOnInit() {
this.ondetails.emit(this.items.length);
}
ngAfterViewInit() {
}
}
layout.component.html
<gridster [options]="options">
<gridster-item *ngFor="let item of layout"
<notifications-widget *ngSwitchCase="'Notifications'"
(ondetails)="item.widgetDetails = $event">
</notifications-widget>
</gridster-item>
</gridster>
widget-creator.component.ts
export class WidgetCreatorComponent implements OnInit {
@Output() onsave = new EventEmitter<any>(null);
widgetType = WidgetType.KPI;
widgetTypes = WidgetTypes;
constructor(private layoutService: LayoutService) { }
save() {
let item: GridsterItem = {
widgetType: this.widgetType,
widgetConfig: this.setWidgetConfig(this.widgetType),
widgetDetails: null,
};
this.layoutService.addItem(item);
this.onsave.emit(this.widgetType);
}
}