0

I'm struggling with change of snackbar(Angular Material) color in Angular. I used panelClass in ts and input it in global css but color doesn't change. How to fix it? Im kinda fresh in this framework.

app.component.ts

import { Component } from '@angular/core';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { MatSnackBarHorizontalPosition } from '@angular/material/snack-bar';
import { MatSnackBarVerticalPosition } from '@angular/material/snack-bar';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  horizontalPosition: MatSnackBarHorizontalPosition = 'center';
  verticalPosition: MatSnackBarVerticalPosition = 'top';
  constructor(private snackBar: MatSnackBar) { }
  openSnackBar(message: string, action: string) {
    this.snackBar.open(message, action, {
      horizontalPosition: this.horizontalPosition,
      verticalPosition: this.verticalPosition,
      panelClass: ['.snackbar-style'],
    });
  }
}

app.component.css

.snackbar-style {
  background-color: black;
  color: hotpink;  
}
            
  • What if you remove the `.` like this: `panelClass: ['snackbar-style']`, maybe the brackets are not needed either – Benny Jan 19 '21 at 06:13
  • Hey check out this post it might help you [Styling Snackbar of Angular Material](https://stackoverflow.com/questions/45439313/angular-2-4-how-to-style-angular-material-design-snackbar) – SBROCKS Jan 19 '21 at 06:17
  • You can simply access by the CSS class selectors. If your lay-out does not apply, then use the `::ng-deep` selector to force the styling. [How and where to use ng-deep?](https://stackoverflow.com/questions/46786986/how-and-where-to-use-ng-deep) – Ruben Szekér Jan 19 '21 at 07:22
  • @RubenSzekér ::ng-deep helped as well thanks – natan0j Jan 20 '21 at 08:25

0 Answers0