0

ERROR TypeError: Cannot read property 'map' of undefined

How to bind dynamic data. I am using angular-tree-grid but i am not able to bind dynamic data.

<html>    
    <db-angular-tree-grid 
        (expand)="onExpand($event)"
        [data]="data" 
        [configs]="configs">
    </db-angular-tree-grid> 
</html>
2
  • Can you explain which code piece is throwing the error? And make sure data is initialized properly. Commented Jan 16, 2020 at 6:40
  • Can you show piece of data? Commented Jan 16, 2020 at 6:45

1 Answer 1

1

Seems like your variable data isn't set initially, and angular-tree-grid tries to .map() something.

Need to see more of your code, but try this:

<db-angular-tree-grid
    *ngIf="data"
    (expand)="onExpand($event)"
    [data]="data" 
    [configs]="configs">
</db-angular-tree-grid>

OR setting a default value as an empty array:

<db-angular-tree-grid
    (expand)="onExpand($event)"
    [data]="data || []" 
    [configs]="configs">
</db-angular-tree-grid>
Sign up to request clarification or add additional context in comments.

1 Comment

this works for me <db-angular-tree-grid (expand)="onExpand($event)" [data]="data || []" [configs]="configs"> </db-angular-tree-grid>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.