Angular 按钮单击打开组件

Angular 按钮单击打开组件,angular,typescript,Angular,Typescript,在我使用Angular的项目中,我希望在单击按钮时它转到另一个组件,但它没有。我将导航方法连接到菜单中的按钮,并编写了该方法,但它没有。我该怎么修理 .html .路由 { path: 'reservationdetail', component: ReservationdetailComponent } .应用程序模块 import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angu

在我使用Angular的项目中,我希望在单击按钮时它转到另一个组件,但它没有。我将导航方法连接到菜单中的按钮,并编写了该方法,但它没有。我该怎么修理

.html

.路由

  { path: 'reservationdetail', component: ReservationdetailComponent }
.应用程序模块

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HotelComponent } from './hotel/hotel.component';
import { ReservationdetailComponent } from ' 
./reservationdetail/reservationdetail.component'; 
import { RezervasyonComponent } from './rezervasyon/rezervasyon.component';

export const routes: Routes = [
{ path: 'hotel', component: HotelComponent },
{ path: "**", redirectTo: "hotel", pathMatch: "full" },
{ path: 'rezervazyon', component: RezervasyonComponent },
{ path: 'reservationdetail', component: ReservationdetailComponent }
];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }

如果只在函数中导航,则不需要在函数中导航。你可以从html导航

<button mat-menu-item [routerLink]="['/reservationdetail']">Reservations List</button>
预订列表

您是否在根级别的app.module.ts中设置了此路由

如果没有,则必须在组件之前路由其他模块

你一定要写得像

this.router.navigate(['/root/parent/../reservationdetail']);

这将工作您需要路由器出口呈现动态路由组件检查您的浏览器控制台是否有任何错误-这可能会有所帮助。或者在这里发布更多的代码,我不会出错。我更详细地编辑了代码。我将其应用于底部,得到了无法绑定到“routerLink”的结果,因为它不是已知的“按钮”错误属性。hocam yardımın Için teşekküller amaşyle bir hata aldım onuızmeyeıalımıyorumşimdi。无法绑定到“routerLink”,因为它不是“button”的已知属性。(“u”>Price Search][routerLink]=“['/reservationdetail']”>预订列表App.modules içine routermodülüimport ettin mi?import{RouterModule}在hattaşimdi de baktım yapmım zaten.App.modules de soru işinde paylaşr mısın?帖子和评论应该是我在hattaşimdi de baktım yapmım zaten.App.modules de soru işinde paylaşr mısın.的帖子和评论。我编辑了代码并分享了它。我安装了应用程序模块。这种方法不起作用,你能告诉我吗将你的应用程序从根目录重新添加到此组件。我这样做是因为通常很容易实现。我正在编写一个酒店项目。当我的页面第一次打开时,有一个按钮。单击该按钮,将显示两个选项。第一个选项是搜索屏幕正常工作的部分,但第二个选项应转到“预订详细信息”页面,但我做不到。我想这就是问题所在,你一定有一些第一页的路径,你能检查一下吗。第一页是否在localhost打开:4200hotel组件在第一页打开。因为我是以root用户身份编写的,你可以查看上面的代码。
<button mat-menu-item [routerLink]="['/reservationdetail']">Reservations List</button>
this.router.navigate(['/root/parent/../reservationdetail']);