我创建了一个“student”组件,当我调用它时,它没有出现在它应该位于的端点中!相反,home组件甚至仍然出现在student端点(/student)中。
学生组件
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-student',
templateUrl: './student.component.html',
styleUrls: ['./student.component.css']
})
export class StudentComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
<p>student works!</p>
app.routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { StudentComponent } from './components/student/student.component';
const routes: Routes = [{ path: 'student', component: StudentComponent },];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
app.component.html
<h1>Grade Management</h1>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'GradeManagement_FrontEnd';
}
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { StudentComponent } from './components/student/student.component';
@NgModule({
declarations: [
AppComponent,
StudentComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
2条答案
按热度按时间nbnkbykc1#
请提供您的app.component.html的内容
实际上,当您启动应用程序时,将加载index.html,并且它应该包含“app-root”标记(项目的文件根)。
toe950272#
谢谢大家,我已经通过将
<router-outlet></router-outlet>
添加到app.component.html