This is my service class method
public getSidebarItems(): Observable<INavData[]> {
// let params = new HttpParams();
// params = params.set('userId', userid.toString());
return this.httpClient.get<Result<INavData[]>> (`${baseUrl}/GetMenusByRoles`)
.pipe(map( res => res.data));
}
This is my json file recieved from api
[{"id":1,"name":"Dashboard","url":"/dashboard","icon":"icon-speedometer","parentId":null,"parent":null,"children":[]},{"id":2,"name":"User","url":"/user/user-list","icon":"icon-list","parentId":null,"parent":null,"children":[]},{"id":3,"name":"Role","url":"/role/role-list","icon":"icon-folder-alt","parentId":null,"parent":null,"children":[]},{"id":4,"name":"Bank","url":"/bank/bank-list","icon":"icon-folder-alt","parentId":null,"parent":null,"children":[]},{"id":5,"name":"Branch","url":"/branch/branch-list","icon":"icon-folder-alt","parentId":null,"parent":null,"children":[]},{"id":6,"name":"Customer","url":"/customer/customer-list","icon":"icon-folder-alt","parentId":null,"parent":null,"children":[]},{"id":7,"name":"Transaction","url":"/transaction/transaction-list","icon":"icon-folder-alt","parentId":null,"parent":null,"children":[{"id":8,"name":"Test","url":"/report/transaction-report\n","icon":"icon-folder-alt","parentId":7,"children":[]}]}]
I have to remove empty "children": []
items$: Observable<INavData[]>;
let result=this.sidebar.getSidebarItems();
this.items$ = result.pipe(
map( sidebarItems => {
return sidebarItems
.filter( value=> Object.keys( value ).length !==0 )
}));
The above code fremove empty
My Question is
- Above code is not working .. i have to removeempty children with node children":[].
Please let me know ..thanks
EDIT:
export interface INavData {
name?: string;
url?: string;
icon?: string;
childrens?: INavData[];
..other property
}
EDIT 1:
After updating code:
result.pipe(
map(x => {
return this.removeEmptyObjects(x);
})
).subscribe(results => { console.log(results); });