繁体   English   中英

单击按钮角度时如何更改组件

[英]How to change component when click on button angular

我正在尝试创建此仪表板,我想知道单击菜单链接时如何更改一个组件? 这是仪表板

我把它分成3个这样的组件

<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>

我想知道如何将(onclick)添加到菜单项并从更改为让我们说并保持相同的布局。 只是为了能够仅将仪表板内容更改为我创建的任何其他组件

如果您已经完成路由,请将此属性添加到 html 按钮标签中

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

或者,在 component.ts 中像这样添加

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

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

btnClick() {
        this.router.navigateByUrl('/content');
};

使用 routerLinkg 等简单的方法

"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM