0

In my project I have menu which is inside *ngFor loop and where I have menu.Id as a parameter to load data from database

<li *ngFor="let item of menu">
  <a [routerLink]="['/products', item .Id]">{{item .Name}}</a>
</li>

when I click this menu item for first time (no matter which one) it works great but after that to click another menu item it not works because ProductsComponent is already loaded and cann't take Id again (route isn't changed '/products/:id' Id is different but constructor is already loaded and component is initialized).

In ProductsComponents' constructor getting data like this

 this.route.params.subscribe(params => {
      this.menuId = params.menuId;
 });
  • How do I can load data dynamically based on route?
  • and is it possible to hide menu.Id in route?
1
  • 1
    Can you show your routing module? Commented Jun 4, 2018 at 19:23

1 Answer 1

1

You can just get the info you need from the route on load

For example, in your ngOnInit you can call getMenuId() with the function:

getMenuId() {
    const id = +this.route.snapshot.paramMap.get('menuId');
    //do something with menuId, like call another function to load your data with the id
  }
Sign up to request clarification or add additional context in comments.

Comments

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.