【发布时间】:2018-08-26 07:42:54
【问题描述】:
父级可复用组件:(settings-panel.component.html)
<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)
<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>
这是我当前的组件scss(outage.component.scss)
:host ::ng-deep app-settings-panel {
div.settings-panel {
right:-1px !important;
top:none !important;
}
button{
background: #152935!important;
padding: 12px !important;
}
}
所以在这里,在我当前的组件中,我正在使用设置面板组件。所以每当hidden attributein parent div 出现在父组件中时,我需要将父按钮背景更改为红色。如果没有,我需要将父按钮的背景更改为绿色?我已经对当前组件进行了更改以执行此操作!
我怎样才能做到这一点?
我想过这样做,但是这个语法错误
//所以当div被隐藏时,我需要让按钮背景发生变化
:host ::ng-deep app-settings-panel div.settings-panel[hidden]{
:host ::ng-deep app-settings-panel button {
background:red;
}
}
如果需要更多解释,请提出建议,以便我可以更清楚地编辑。
任何帮助将不胜感激!
【问题讨论】:
-
这有点令人困惑......你的标题提到根据
hidden属性修改css,但在你的问题中你要求open (not hidden)。为什么不改变父组件的按钮样式呢? -
@David 当(隐藏或不隐藏)显示发生任何变化时,我需要更改样式。我不在父组件中做,因为它是一个常见的可重用组件。以上案例只针对我当前的组件。
-
是什么导致了您的问题?更改检测或 jsut 将 css 放在哪里?
-
@David 我现在已经修改了。你现在可以检查一下吗?
标签: javascript css angular sass styles