2

tl;dr: Very simple component displays only once. WHY?

I have this component:

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

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

export class AppComponent {
    pageTitle: string = "Title";
 }

And I use it in the following page (Index.html):

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

The page displays "Title" (obviously). But if I change the html to:

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

It still displays "Title", just once. Shouldn't it display it twice?

Sam
  • 144
  • 3
  • 3
    Where are you putting this `` element? If you are putting it in the `index.html` it will not work. – penleychan Oct 05 '18 at 16:29
  • @penleychan yes, it's in index.html, so is that an angular thing? Do I have to create another component to host multiple instances of the same component? – Sam Oct 05 '18 at 17:09
  • yes, absolutely right. in index.html there should be only one component that is . You can use this type of approach where you have the component, there you can use the two components like – Arghya Chowdhury Feb 04 '19 at 06:39

0 Answers0