Angular 关于组件的角度绝对新手问题

Angular 关于组件的角度绝对新手问题,angular,Angular,tl;dr:非常简单的组件只显示一次。为什么? 我有这个部分: import { Component } from "@angular/core"; @Component({ selector: 'testComponent', template: '<div><h1>{{pageTitle}}</h1></div>' }) export class AppComponent { pageTitle: string

tl;dr:非常简单的组件只显示一次。为什么?

我有这个部分:

import { Component } from "@angular/core";

@Component({
    selector: 'testComponent',  
    template: '<div><h1>{{pageTitle}}</h1></div>'
})

export class AppComponent {
    pageTitle: string = "Title";
 }
从“@angular/core”导入{Component};
@组成部分({
选择器:“testComponent”,
模板:“{pageTitle}}”
})
导出类AppComponent{
pageTitle:string=“Title”;
}
我在下面的页面(Index.html)中使用它:


页面显示“标题”(显然)。但如果我将html更改为:

<html>
  <body>
      <testComponent></testComponent>
      <testComponent></testComponent>
  </body>
</html>


它仍然只显示一次“标题”。它不应该显示两次吗?

您将这个
元素放在哪里?如果你把它放在
index.html
中,它将不起作用。@penleychan是的,它在index.html中,那么这是一件有角度的事情吗?我是否必须创建另一个组件来承载同一组件的多个实例?是的,绝对正确。在index.html中,应该只有一个组件是。您可以在有组件的地方使用这种方法,在那里您可以使用两个组件,如
<html>
  <body>
      <testComponent></testComponent>
      <testComponent></testComponent>
  </body>
</html>