有没有办法在Angular 2或更高版本的html上显示组件名称?

前端之家收集整理的这篇文章主要介绍了有没有办法在Angular 2或更高版本的html上显示组件名称?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这个组件……

<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>

解决方法

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

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

否则,根据this page

Directives that replace their host element (replace: true directives in Angular 1) are not supported in Angular 2. In many cases these directives can be upgraded over to regular component directives.

猜你在找的Angularjs相关文章