Angular 角度元素:即使是空的插槽也会出现

Angular 角度元素:即使是空的插槽也会出现,angular,web-component,angular-elements,Angular,Web Component,Angular Elements,我正在使用Angular元素创建UI工具包。我正在使用插槽进行内容投影。问题是每当我使用插槽时,当插槽内容为空时,插槽的dom元素仍然存在 下面是我正在使用的UI组件的代码 <div class="portlet"> <div class="portlet-header-top"> <slot class="portlet-header__icon" name="header_icon"> </slot> &l

我正在使用Angular元素创建UI工具包。我正在使用插槽进行内容投影。问题是每当我使用插槽时,当插槽内容为空时,插槽的dom元素仍然存在

下面是我正在使用的UI组件的代码

<div class="portlet">
 <div class="portlet-header-top">
      <slot class="portlet-header__icon" name="header_icon">
      </slot>
      <slot class="portlet-header__title" name="header_top_title">
      </slot>
      <slot class="portlet-header__right" name="header_top_right">
      </slot>
    </div>
    <div class="portlet-header-bottom">
      <slot class="portlet-header__title" name="header_bottom_title"></slot>
    </div>
</div>

在这个例子中,即使用户没有使用header\u图标、header\u top\u title、header\u top\u right slots->这些slots已经被注入到DOM中(还有一些样式,比如边距、背景-这使得元素看起来很难看)


对此我能做些什么?

我通过在css中使用:slotting()选择器解决了这个问题。这是设置开槽内容样式的唯一方法。您可以参考关于:slotting()

我使用css中的:slotting()选择器修复了这个问题。这是设置开槽内容样式的唯一方法。您可以参考关于:slotting()

如果问题令人困惑,请随意编辑:)如果问题令人困惑,请随意编辑:)