In angular I have the following logic in a component:
menu: Array<object> = [];
ngOnInit() {
this.menu.push(
...HomeMenu,
...QuickReferenceMenu
);
console.log(this.menu);
}
The menu property gets the following constants that it destructures:
export const HomeMenu: Array<object> = [
{ path: '', name: 'Home', direct: true }
];
export const QuickReferenceMenu: Array<object> = [
{
path: 'quck-reference',
name: 'Quick Reference',
children: [
{
path: 'combat',
name: 'Combat'
}
]
}
];
and in a template I just do the following
<div *ngFor="let item of menu">
asd
</div>
Instead of working properly I get the following error: "Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays." You can notice the console log up there.
It is indeed an array.
Also the module governing this component imports CommonModule from angular
import { NgModule } from '@angular/core';
import { NavigationComponent } from './navigation.component';
import { MatMenuModule } from '@angular/material/menu';
import { MatButtonModule } from '@angular/material/button';
import { CommonModule } from '@angular/common';
@NgModule({
declarations: [ NavigationComponent ],
imports: [ MatMenuModule, MatButtonModule, CommonModule ],
exports: [ NavigationComponent ]
})
export class NavigationModule {}
I am at a loss. I really dont understand why such a simple operation is failing.
Edit: Im adding the repo https://github.com/Panglot/DnD_app
menu
when it is initialised. That's the reason when it is rendering the DOM, there is no value present in menu and so it throws the error. just define it asmenu=[ {name:" ", path:" "}]
the{name:"",path:""}
will repeat for the number of times it is expected to get a value. – Richard Pariath