Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeating root tag in index.html

Tags:

angular

Why does repeating <app-root> tag in my index.html have no effect? For example, if my app.component.html has a simple Hello World and if I write

<app-root></app-root>
<app-root></app-root>
<app-root></app-root>

in index.html, the browser displays only one Hello World and not

Hello World
Hello World
Hello World
like image 879
codingsplash Avatar asked Apr 05 '26 23:04

codingsplash


1 Answers

That's because angular selects root element through:

document.querySelector(selectorOrNode)

where selectorOrNode is the root component selector.

As you can guess it will always return only first element.

If you want to apply root component to several elements then you can use ngDoBootstrap as described here:

  • Is it possible to run one Angular 2 app several times in one page?
like image 122
yurzui Avatar answered Apr 08 '26 15:04

yurzui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!