angular - angular 6 用条件覆盖 css
问题描述
我ng-select
在我的项目中使用过,我使用 删除了交叉清除图标,并且我还通过覆盖类[clearable]="false"
删除了每个项目的清除图标ng-value-icon
:host ::ng-deep .ng-value-icon {
display: none !important;
}
我想用条件应用css
constructor() {
if(this.result === "ok") {
//apply the css
}
}
解决方案
模板的这一部分(来自您的 Stackblitz)决定类custom
与名为的作用域变量有关step
:
[class.custom]="step === 'step1'"
所以,使用它:
step: 'step1'|'not-step1' = 'not-step1';
constructor() {
if(this.result === "ok") {
this.step = "step1";
}
}
或者您将模板中的条件更改为
[class.custom]='result === "ok"'
或者,很可能比这个 css-toggle 更好,你可以使用*ngIf
*ngIf="result === 'ok'"
.
推荐阅读
- ios - 使用 Mapbox 时,是否可以在有限区域内滚动?
- arrays - VB.NET 中括号的放置如何影响数组(在实际程序中)?
- python - PIL 图像打开将白色像素变成黑色像素
- javascript - 使用来自 react-router 的 onClick 链接
- python - 带点的 Python 函数
- c++ - 如何在 C++ 中的 const unordered_map 上使用“[]”运算符?
- python - 如何将 kwargs 从装饰器传递给装饰器?
- android-studio - 应用程序在不同设备上的行为不同
- spring - 将 Spring 异常传递给 Thymeleaf 页面
- php - 无法使用 CustomRequest 验证 Laravel 请求。我收到 MethodNotAllowedHttpException