I am new to Angular2/4 and angular typescript. I want to style the angular material design snackbar for example change the background color from black and font
::ng-deep support will be dropped, as announced any time soon. Set encapsulation: ViewEncapsulation.None on your message bar component, and you are good to go:
import { Component, Inject, OnInit, ViewEncapsulation } from '@angular/core';
import { MAT_SNACK_BAR_DATA } from '@angular/material';
import { MessageBarType } from './message-bar.model';
@Component({
selector: 'app-message-bar',
templateUrl: 'message-bar.component.html',
styleUrls: ['message-bar.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class MessageBarComponent implements OnInit {
public MessageBarType: typeof MessageBarType = MessageBarType;
constructor(@Inject(MAT_SNACK_BAR_DATA) public data: { text: String, type: MessageBarType }) { }
ngOnInit() {
}
}
Then in your scss file:
@import '~@angular/material/theming';
@import '~app/theme-defs';
snack-bar-container {
&.error {
background-color: mat-color($warn);
}
&.warning {
background-color: mat-color($dark-warn);
}
&.info {
background-color: mat-color($accent);
}
}