在index.html中重复根标签 [英] Repeating root tag in index.html

查看:87
本文介绍了在index.html中重复根标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在index.html中重复<app-root>标记无效?例如,如果我的app.component.html具有简单的Hello World且我编写

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>

在index.html中,浏览器仅显示一个Hello World,而不显示

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

Hello World
Hello World
Hello World

推荐答案

这是因为angular通过以下方式选择了根元素:

That's because angular selects root element through:

document.querySelector(selectorOrNode)

其中selectorOrNode是根组件选择器.

您可能会猜到它总是只返回第一个元素.

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

如果要将根组件应用于多个元素,则可以按照以下说明使用ngDoBootstrap:

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

这篇关于在index.html中重复根标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆