我正在 angular.io 上做官方的“英雄之旅”Angular 教程。
添加一个名为“英雄”的模块并显示它后,一切都很好。heros.component.html 只包含一个 p-tag 说“英雄有用!”。当我更改它时,我的应用程序将得到更新,但它不会更新在 hero.component.html 中所做的更改。因此,即使项目中不再写“英雄作品”,应用程序仍会显示该消息。我真的很感谢你的帮助。
hero.component.ts:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-heroes',
templateUrl: './heroes.component.html',
styleUrls: ['./heroes.component.css']
})
export class HeroesComponent implements OnInit {
hero = 'windstorm';
constructor() { }
ngOnInit() {
}
}
hero.component.html:
<h2>{{hero}}</h2>>
app.component.html:
<h1>{{title}}</h1>
<app-heroes></app-heroes>
app.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'tour';
}
app.module.ts:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes/heroes.component';
@NgModule({
declarations: [
AppComponent,
HeroesComponent
],
imports: [
BrowserModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }