如何根据条件应用 ng-deep?

5

例子 -> 在父组件中

<div class="if-this-class-is-applied">
<child></child> 
</div>

如果只应用上述类,则应触发"子组件"的ng deep。


1
你尝试过什么?你尝试过这个吗,如果应用了这个类 ::ng-deep? - Chellappan வ
2个回答

6
::ng-deep .if-this-class-is-applied > child {
 // Your styles 
}

0
另一种方法是这样做。假设你有以下的结构。
<div>
   <child [ngClass]="{ 'your-class-name': condition }"></child> 
</div>

在CSS中,你可以修改子组件的类,例如:
.your-class-name {
  ::ng-deep {
    .child-component-class-you-want-to-alter {
       max-width: 340px;
      }
    }
  }

这将仅根据条件设置最大宽度。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接