【发布时间】:2022-01-11 23:50:05
【问题描述】:
在 Angular2 项目中,我需要对按钮应用一些 CSS。 我想在 .html 中添加一个类并在 .scss 文件中描述所有样式属性,但不幸的是,这个元素“没有”看到该类。 但是,只要我在 .html 文件中添加与内联样式相同的样式 - 一切正常。
我想替换这段代码(来自下面的 sn-p,第 5 行)
[ngStyle]="{ position: 'absolute', 'z-index': '10', right: '0' }"
通过这个class="test-class"
并使用 .scss 文件中 test-class 的数据。
stackblitz 的链接 https://stackblitz.com/edit/angular-ivy-avvwha?file=src%2Fapp%2Fapp.component.html
.html
<div>
<gridster [options]="options">
<gridster-item [item]="item" *ngFor="let item of dashboard">
<div
[ngStyle]="{ position: 'absolute', 'z-index': '10', right: '0' }"
>
<button mat-mini-fab>
<mat-icon>delete</mat-icon>
</button>
</div>
<ng-container>
<div class="outline">
<div class="header">
<div class="header-text">Text</div>
</div>
</div>
</ng-container>
</gridster-item>
</gridster>
</div>
.scss
.test-class {
position: 'absolute';
z-index: 10;
right: 0;
}
也许还有其他选项可以从 .html 文件中删除样式,但我忽略了它。
提前谢谢你!
【问题讨论】:
标签: html css angular inline-styles