как я могу использовать роутер-розетку в двух разных компонентах? Я использовал app.component и теперь хочу использовать его в Public2, но я ошибаюсь.
ERROR in src/public2/public2.component.html:4:1 - error NG8001: 'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular component, then verify that it is part of this module.
2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
4 <router-outlet></router-outlet>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/public2/public2.component.ts:5:16
5 templateUrl: './public2.component.html',
~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component Public2Component.
Сценарий проекта:
<h2>appHeader</h2>
<router-outlet></router-outlet>
<h2>app footer</h2>
app-routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import{AdminComponent} from './Layout/admin/admin.component';
import{PublicComponent} from './Layout/public/public.component';
import {Public2Component} from '../public2/public2.component';
const routes: Routes = [
{path:'',component: PublicComponent},
{path:'Admin',component: Public2Component}
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import {HttpClientModule} from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatSliderModule } from '@angular/material/slider';
import {FormsModule, ReactiveFormsModule} from '@angular/forms'
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AboutMeComponent } from './about-me/about-me.component';
import { PersonalServiceService } from './personal-service.service';
import { MessageComponent } from './message/message.component';
@NgModule({
declarations: [
AppComponent,
AboutMeComponent,
MessageComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
HttpClientModule,
ReactiveFormsModule,
BrowserAnimationsModule,
MatSliderModule
],
providers: [PersonalServiceService],
bootstrap: [AppComponent]
})
export class AppModule { }
Public2.component. html:
<h1>public2 Header</h1>
<a routerLink="test">Go test</a>
<router-outlet></router-outlet>
<h1>public2 Footer</h1>
Public2 .module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Public2RoutingModule } from './public2-routing.module';
import { Public2Component } from './public2.component';
import { TestComponent } from './test/test.component';
@NgModule({
declarations: [Public2Component, TestComponent],
imports: [
CommonModule,
Public2RoutingModule
]
})
export class Public2Module { }
public2-routing.module.ts:
import { TestComponent } from './test/test.component';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{path:'test',component:TestComponent}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class Public2RoutingModule { }
Проект запускается, но когда я нажимаю на тест routerlink, ничего не происходит, и он не ' t введите компонент test.com, и адрес URL не изменится.