首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从子组件更改父可重用组件的样式?

如何从子组件更改父可重用组件的样式?
EN

Stack Overflow用户
提问于 2018-03-17 14:48:45
回答 1查看 98关注 0票数 0

我在当前的组件中使用了一个可重用的组件。但是我想改变我的可重用组件的样式。如何重写子组件中的父级可重用组件样式。

父可重用组件:(settings-panel.Component.html)

代码语言:javascript
复制
<button>
    <app-svg-icon [iconSrc]="iconSrc"></app-svg-icon>
</button>
<div [ngClass]="position" class="settings-panel" [hidden]="!panelIsVisible">
    <span class="arrow"></span>
    <ng-content></ng-content>
</div>

这是我当前的组件(outage.component.html)

代码语言:javascript
复制
 <app-settings-panel class="outage-main" iconPath="alert.svg" position="right bottom">
     <div class="outage-panel">
        <div class="outage-heading">
            <span>Notifications</span>
            <span>New</span>
        </div>      
        <span *ngFor="let outage of outageArray">
            <button type="button" class="outage-group-item">
                <span>{{outage}}</span>
            </button>
        </span>
     </div>
 </app-settings-panel>

这是我当前的组件(outage.component.scss)

代码语言:javascript
复制
.outage-main{
    div:nth-child(1) {
            border: 5px solid red !important; 
    }
}

在这里,我尝试更改父组件的div样式。但是它并没有改变父div的样式。它正在改变我当前组件中div的样式。

如何更改我的settings-panel.component.html中的样式?

EN

回答 1

Stack Overflow用户

发布于 2018-03-17 15:37:17

根据@vega的评论,我读到:host,这解决了我的问题

代码语言:javascript
复制
 :host ::ng-deep app-settings-panel {

      div.settings-panel {
          border: 5px solid red !important;
      }
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49333332

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档