我正在try 调用3个不同的标签使用Angular 布线.我使用工具栏垫来显示.我遵循了YouTube https://www.youtube.com/watch?v=ADEZTrIxj1k&ab_channel=TechnophileProgBox教程中的步骤.

在我编程时,导航使用的是一个组件.现在,它不再与任何一家公司合作.

我已经搜索了Stackoverflow的解决方案,但没有找到任何东西,您能帮助我吗?

app.component.html

<app-navbar></app-navbar>
<router-outlet></router-outlet>

navbar.component.html

<mat-toolbar color="primary" class="mat-elevation-z8">
    <span><mat-icon>euro_symbol</mat-icon> Rechnungen</span>
    <div class="spacer"></div>
    
    <a mat-button router-link="/customers">Kunden</a>
    <a mat-button router-link="/articles">Artikel</a>
    <a mat-button router-link="/invoices">Rechungen</a>

</mat-toolbar>

app-routing.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CustomersComponent } from './customers/customers.component';
import { InvoicesComponent } from './invoices/invoices.component';
import { ArticlesComponent } from './articles/articles.component';

const routes: Routes = [
  {path: 'invoices', component:InvoicesComponent},
  {path: 'articles', component:ArticlesComponent},
  {path: 'customers', component:CustomersComponent}
];

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

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppRoutingModule } from './app-routing.module';
import {MatToolbarModule} from '@angular/material/toolbar';
import {MatButtonModule} from '@angular/material/button';
import {MatIconModule} from '@angular/material/icon';

import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NavbarComponent } from './navbar/navbar.component';
import { ArticlesComponent } from './articles/articles.component';
import { InvoicesComponent } from './invoices/invoices.component';
import { CustomersComponent } from './customers/customers.component';


@NgModule({
  declarations: [
    AppComponent,
    NavbarComponent,
    ArticlesComponent,
    InvoicesComponent,
    CustomersComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    MatToolbarModule, //import mattoolbar 
    MatButtonModule,
    MatIconModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

``folder structure` folder-structure

推荐答案

你好像打错了:router-link应该是routerLink

Typescript相关问答推荐

在TypScript手册中可以视为接口类型是什么意思?

React组件数组及其props 的类型定义

React-Native运行方法通过监听另一个状态来更新一个状态

为什么typescript不能推断类的方法返回类型为泛型''

为什么TypeScript失go 了类型推断,默认为any?''

react 路由6操作未订阅从react 挂钩表单提交+也不使用RTK查询Mutations

如何使用函数填充对象?

带switch 的函数的返回类型的类型缩小

通过字符串索引访问对象';S的值时出现文字脚本错误

从子类构造函数推断父类泛型类型

为什么我的一个合成函数不能推断类型?

如何使用模板继承从子组件填充基础组件的画布

如何从输入中删除值0

是否有可能避免此泛型函数体中的类型断言?

如何按属性或数字数组汇总对象数组

界面中数组中的混合类型导致打字错误

错误TS7030:并非所有代码路径都返回值.";由tsfig.json中的";Strong";:False引起

如何调整项目数组,但允许权重影响顺序

Angular另一个组件的nativeelement未定义

可选通用映射器函数出错