正如你可以在开发者控制台Can't bind to 'hero' since it isn't a known property of 'my-hero-detail'.
错误是<my-hero-detail [ERROR ->][hero]="selectedHero"></my-hero-detail>
因为你没有在HeroDetailComponent
添加@Input
装饰到hero
属性看。您还没有将<base href="/">
加入index.html
。
hero.detail.component.ts
import { Component, OnInit, Input } from '@angular/core';
//...
@Component({
moduleId: module.id,
selector: 'my-hero-detail',
templateUrl: './hero-detail.component.html'
})
export class HeroDetailComponent implements OnInit {
@Input() private hero: Hero;
//...
}
的index.html
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
<base href="/">
<!-- ... -->
</head>
<body>
<my-app>Loading AppComponent content here ...</my-app>
</body>
</html>
读Component Communication教程。
您的控制台出现错误。你为什么不在你的问题中提供它? – echonax
实际上,当我执行'npm start'时,我没有注意到任何错误,所以这就是让我困惑的原因 – guchuan
您应该从浏览器控制台添加错误消息) – Saka7