siw*_*iw6 2 typescript angular-material angular
我想在 MatSnackBar panelClass 中插入一个 scss 类。但它没有工作。仅供参考,verticalPosition 和 horizontalPosition 工作正常。这是我的 TS:
openSnackBar(message: string, action: any) {
this.snackBar.open(message, action, {
duration: 2000,
verticalPosition: 'top',
horizontalPosition: 'center',
panelClass: ['alert-red'],
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的 Scss:
.alert-red{
padding: 20px;
background-color: red;
color: white;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
如果你在你的班级前面加上以下前缀,它似乎有效::ng-deep snack-bar-container(请参阅此评论)。所以你的组件 SCSS 文件应该是这样的:
::ng-deep snack-bar-container.alert-red{
padding: 20px;
background-color: red;
color: white;
}
Run Code Online (Sandbox Code Playgroud)
变通方法:请参阅此处的帖子,您似乎需要将样式放在应用程序styles.scss文件中,而不是放在组件 SCSS 文件中。
检查此stackblitz,样式styles.scss在app.component.scss. 不确定这是错误还是预期行为。
| 归档时间: |
|
| 查看次数: |
5259 次 |
| 最近记录: |