2

I am trying to create this dashboard and i want to know how to change one component when a menu link is clicked? This is dashboard

I split it in 3 components like that

<div id="wrapper">
  <app-dashboard-menu></app-dashboard-menu>
  <div id="content-wrapper" class="d-flex flex-column">
    <div id="content">
      <app-dashboard-topbar></app-dashboard-topbar>
      <app-dashboard-content></app-dashboard-content>
    </div>
  </div>
</div>

i want to be know how can i add (onclick) to a menu item and change from to lets say and keep the same layout. Just to be able to change only dashboard content to any other component i create

1 Answer 1

5

if you already had finished routing, add this property into html button tag

<button type="button"  routerLink="/content">Content</button>

or, add like this in component.ts

<button type="button" (click)="btnClick()">Content</button>    

import { Router } from '@angular/router';

btnClick() {
        this.router.navigateByUrl('/content');
};
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but i used router outlet and declared them as children of the dashboard component
yeah, also the router outlet need is need for my answer. sorry, I couldn't mention it before

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.