如何渲染一个组件而不包括其包装标签

huangapple go评论56阅读模式
英文:

How to render a component without its wrapping tag

问题

<div class='w-full flex relative'>
    <!-- search component -->
    <app-search></app-search>
    <div class='absolute right-0 flex justify-end gap-6'>
        <!-- manipulate nav component-->
        <app-manipulate-nav></app-manipulate-nav>
    </div>
</div>

这段代码看起来不如预期工作。我的页面应该是这样的如何渲染一个组件而不包括其包装标签,但实际渲染结果却是这样的如何渲染一个组件而不包括其包装标签,这是因为组件包装标签的原因。

我已经尝试在开发工具中移除组件标签(使用ctrl+shift+I),那样可以正常工作,还尝试了ng-container,但没有成功。是否有其他方法来渲染这个内容?

英文:
&lt;div class=&#39;w-full flex relative&#39;&gt;
        &lt;!-- search component --&gt;
        &lt;app-search&gt;&lt;/app-search&gt;
        &lt;div class=&#39;absolute right-0 flex justify-end gap-6&#39;&gt;
            &lt;!-- manipulate nav component--&gt;
            &lt;app-manipulate-nav&gt;&lt;/app-manipulate-nav&gt;
        &lt;/div&gt;
   &lt;/div&gt;

This is not working as expected
my page should be this 如何渲染一个组件而不包括其包装标签
but it render like this 如何渲染一个组件而不包括其包装标签
because of component wrapping tag

I have tried to remove component tag on inside devtools(ctrl+shift+I) that was working and i have tried ng-container but that does not work. Any other way to render this??

答案1

得分: 1

只需尝试直接在您的 app-manipulate-nav 组件上应用您的 CSS。

<div class='w-full flex relative'>
    <!-- 搜索组件 -->
    <app-search></app-search>

    <app-manipulate-nav class='absolute right-0 flex justify-end gap-6'></app-manipulate-nav>
</div>

如果这不起作用,您需要共享您的子组件的HTML和CSS。这是一个CSS问题,没有必要“删除标记”(顺便说一句,这是不可能的)。将标记视为一个完全未经样式化的HTML元素。

英文:

Just try and apply your CSS directly on your app-manipulate-nav component.

&lt;div class=&#39;w-full flex relative&#39;&gt;
        &lt;!-- search component --&gt;
        &lt;app-search&gt;&lt;/app-search&gt;

        &lt;app-manipulate-nav class=&#39;absolute right-0 flex justify-end gap-6&#39;&gt;&lt;/app-manipulate-nav&gt;
   &lt;/div&gt;

If it doesn't do the trick, you'll need to share you child component's HTML and CSS. This is a CSS issue, there's no need to "remove the tag" (which is impossible by the way). See the tag as a completely unstyled HTML element.

huangapple
  • 本文由 发表于 2023年7月13日 21:31:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76679928.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定