【问题标题】:Is there some way to don't show the component name on the html in Angular 2 or superior?有没有办法不在 Angular 2 或更高版本的 html 上显示组件名称?
【发布时间】:2018-06-15 03:39:00
【问题描述】:

这个组件...

<my-component>
   <p>Hello !</p>
</my-component>

...在 html 模板内...

<div class="myClass">
   <my-component></mycomponent>
</div>

...将在客户端呈现类似这样的内容:

<div class="myClass">
   <my-component>
     <p>Hello !</b>
  </mycomponent>
</div>

有什么方法可以不显示组件的html标签,而是显示组件的内部内容吗?比如……

<div class="myClass">
      <p>Hello !</b>
</div>

【问题讨论】:

  • 这个问题你得到答案了吗

标签: angular angular-components


【解决方案1】:

既然你有一个选择器,你可以尝试做

<div class="myClass">
   <div my-component></div>
</div> 

否则根据this page

Angular 2 不支持替换其宿主元素的指令(在 Angular 1 中替换为 true 指令)。在许多情况下,这些指令可以升级为常规组件指令。

【讨论】:

  • 这与迁移策略无关,抱歉。
  • 我正在使用一个可能使用伪类 first-child 的框架......这会导致意外行为,因为 first-child 将是 html 中的组件选择器标记:(跨度>
  • 我知道这与迁移无关,我只是告诉你与 AngularJS 不同,Angular 不允许标记替换。我看到了您的问题,您能否在您的帖子中提供更多有关此问题的信息,以便我们专注于如何纠正它而不是如何更改 Angular ? :)
猜你喜欢
  • 1970-01-01
  • 2023-01-17
  • 2021-08-10
  • 2011-03-01
  • 2023-02-06
  • 2018-01-11
  • 2022-11-02
  • 2021-12-12
  • 1970-01-01
相关资源
最近更新 更多