if (index > -1) {
this.areas.splice(index, 1);
this.dashboardConfiguration.widgets.forEach(wAId => {
const allWidgetByAreaId = wAId.widgets.filter(w => w.areaId === area.id);
allWidgetByAreaId.forEach(w => {
w.areaId = null;
});
});
}``` Here is my code, I have (widgets which is WidgetAccess[]) and it contains widgets[]. The problem is area.id is undefined so I cant have w.areaId = null. Would you please heip? Would you please help me?
#Nested loops give me undefined!
12 messages · Page 1 of 1 (latest)
g!codeblock @hallow shale
@hallow shale, you can use the following snippet to have your code formatted and colored by Discord. Replace ts with the language you need (i.e. html, js, css, etc)
```ts
// your code goes here
```
And please indent your code so it's easier to read.
About your problem
what exactly is the issue?
If your area.id is undefined, whole loop will not even start unless one of your widgets has id property set to undefined
Thank you. This is the complete code: ```ts
RemoveArea(area: models.Area) {
let messages: string[] = [];
messages = messages.concat(this.getMessagesFromDeletingArea(area));
this._translate.get('QuestionGroup_RemoveAreaConfirm',
{ thisCaption: area.caption[this.BlueContext.currentLanguage] }).subscribe(nextCaption => {
this.dialogsService.confirm(nextCaption, messages)
.subscribe(confirmed => {
if (confirmed) {
this._areaService.removeArea(this.dashboardConfiguration, area, this.BlueContext.currentLanguage);
const index = this.areas.findIndex(a => a.id === area.id);
if (index > -1) {
this.areas.splice(index, 1);
this.dashboardConfiguration.widgets.forEach(wAId => {
const allWidgetByAreaId = wAId.widgets.filter(w => w.areaId === area.id);
allWidgetByAreaId.forEach(w => {
w.areaId = null;
});
});
}
}
});
});
}
Please put ts beside opening three ticks for syntax highlighting.
Then it means that your call to RemoveArea is not passing a valid argument.
Aside from that, there are a lot of bad practices in your code.
You should not nest subscribing,s on top of anything else.
You got to use RxJs operators.