0

hello I have a sidebar component which must have a menu tree that allows navigating between the pages, so I thought to use angular material tree since the project is in material, I need that when seeing the options of a node you can navigate to that view , I know that with routerlink in the html it is possible but since the tree loads the data is from the .ts, the menu is static they will always do the same options this is the example most similar to what I want from time to time. but I need the navigation in the node options

https://stackblitz.com/edit/angular-qsb9c8-x4oaan

1
  • Can you please show what you have tried till now? Commented Jul 22, 2020 at 14:17

1 Answer 1

2

As per my understanding you want to visit the pages by clicking on the menu items.

So for that you can maintain the paths in the object itself which you are using in the for loop. As per the example you have used. I am showing you the updated object that you have to replace.

export class FileNode {
  children: FileNode[];
  filename: string;
  type: any;
  path:string;
}

Applications: {
    Calendar: 'app',
    Chrome: 'app',
    Webstorm: 'app',
    path:'abc'
  }

And you can use this path in the html for routing purpose. Here I am showing you the example that you can refer.

 <mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
    <li class="mat-tree-node">
         <a  [routerLink]="[node?.path]">
      {{node.filename}}:  {{node.type}}</a>
    </li>
  </mat-tree-node>
Sign up to request clarification or add additional context in comments.

3 Comments

try this solution but the path is undefined when adding it to the object, if the path put it in the routerlink of the html if navigation works, also when adding that property path the path and route are displayed in the view as an option of the node in any case should be hidden
Have you added one more field in the model for path? And in html you can also call the method for navigating to the desired path.
yes this.router.navigate works for me !! add a click event in the mat-tree-node send the node I receive it as an argument in a method in the ts! thank you very much for your help

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.