我正在学习Angular并且相当新。我目前正在处理一个项目,刚刚完成了我的路由设置,但现在我无法在内容位于app.component之前看到网页上的任何内容。 html文件。
然后将其移动到buttons.component.ts文件中的模板。
有人可以告诉我为什么没有输出?
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import {Routes, RouterModule} from '@angular/router';
import { AppComponent } from './app.component';
const routes: Routes= [
{path: 'demo', loadChildren: './demo/demo.module#DemoModule'},
{path: '**', redirectTo: 'demo'}
]
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
RouterModule.forRoot(routes),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
---- demo.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MaterialModule } from '../shared/material.module';
import { FormsModule } from '@angular/forms';
import { DemoRoutingModule } from './demo-routing.module';
import { ButtonsComponent } from './buttons/buttons.component';
import { FlexboxComponent } from './flexbox/flexbox.component';
@NgModule({
imports: [
CommonModule,
DemoRoutingModule,
FormsModule,
MaterialModule
],
declarations: [ButtonsComponent, FlexboxComponent]
})
export class DemoModule { }
---- demo.routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import {ButtonsComponent} from './buttons/buttons.component';
import {FlexboxComponent} from './flexbox/flexbox.component';
const routes: Routes = [
{path: 'buttons', component: ButtonsComponent},
{path: 'flexbox', component: FlexboxComponent},
{ path: '**', redirectTo: 'buttons'}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class DemoRoutingModule { }
----- buttons.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-buttons',
template: `
<button mat-button>
<mat-icon>face</mat-icon>
Click me!
</button>
<mat-checkbox>Check me!</mat-checkbox>
`,
styles: []
})
export class ButtonsComponent {
}