【问题标题】:angular4:ng-content nested class based selectionangular4:ng-content 基于嵌套类的选择
【发布时间】:2018-05-15 06:02:31
【问题描述】:

众所周知,Angular4 支持ng-content

这里我们可以根据classelement-nameattributes进行选择。

我正在尝试根据类选择元素: 这是我的消费者组件 html:

 <my-component>
      <div class = "item">
        <div class = "item-small">small-item content</div>
     <div class = "item-large">large-item content</div>
    </div>

</my-component> 

现在在我的my-component 模板中,我正在尝试使用item-small 类访问div

我的my-component 模板如下所示:

<div class="my-component">
   <ng-content select = ".item>.item-small"></ng-content>
</div>

但它没有给我任何回报。 这是这个问题的关键:

https://plnkr.co/edit/2hlL2GezNXRoLCD1FAPD?p=preview

处理此类情况的最佳选择是什么?

请给出正确的方法来解决这个问题。

【问题讨论】:

    标签: javascript angular angular2-template angular2-directives


    【解决方案1】:

    我很确定只支持直接匹配元素的选择器

    这应该可以工作

    ".item-small"
    

    但这不是

    ".item>.item-small"
    

    类似于元素或指令选择器。

    【讨论】:

    • 这不起作用。我已经编辑了我的问题,以便为这个问题提供解决方案。
    猜你喜欢
    • 2019-07-11
    • 2016-09-23
    • 2015-11-18
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 2018-01-02
    相关资源
    最近更新 更多