[英]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.