@javaflex valeu.
Antes estava assim:
import { Component } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'app-snack-bar',
templateUrl: './snack-bar.component.html',
styleUrls: ['./snack-bar.component.scss']
})
export class SnackBarComponent {
timeOut = 1500;
constructor(public snackBar: MatSnackBar) { }
openSnackBar(
message: string,
className?: string,
action?: string,
verticalPosition?: any,
horizontalPosition?: any
) {
className = className !== null || className !== undefined ? 'mat-snack-bar-container-' + className : className;
verticalPosition =
verticalPosition === null || verticalPosition === undefined
? 'bottom'
: verticalPosition;
horizontalPosition =
horizontalPosition === null || horizontalPosition === undefined
? 'center'
: horizontalPosition;
this.snackBar.open(message, action, {
duration: this.timeOut,
verticalPosition: verticalPosition,
horizontalPosition: horizontalPosition,
panelClass: [className],
});
}
}
Alterei para:
Funcionou. Mas não conseguir passar as mensagens que vem do backend para o componente.
Fiz assim:
import { Component } from ‘@angular/core’;
import { MatSnackBar } from ‘@angular/material/snack-bar’;
@Component({
selector: 'app-snack-bar',
templateUrl: './snack-bar.component.html',
styleUrls: ['./snack-bar.component.scss']
})
export class SnackBarComponent {
timeOut = 1500;
constructor(public snackBar: MatSnackBar) { }
openSnackBar(
message: string,
className?: string,
action?: string,
verticalPosition?: any,
horizontalPosition?: any
) {
className = className !== null || className !== undefined ? 'mat-snack-bar-container-' + className : className;
verticalPosition =
verticalPosition === null || verticalPosition === undefined
? 'bottom'
: verticalPosition;
horizontalPosition =
horizontalPosition === null || horizontalPosition === undefined
? 'center'
: horizontalPosition;
this.snackBar.openFromComponent(snackBarPartyComponent, {
duration: this.timeOut,
verticalPosition: verticalPosition,
horizontalPosition: horizontalPosition,
panelClass: [className]
});
}
}
@Component({
selector: 'snack-bar-party-component',
templateUrl: 'snack-bar-party-component.html',
})
export class snackBarPartyComponent {}
snack-bar-party-component.html
<span>
{{announcementMessage}}
</span>
A variável message tem que chegar no snack-bar-party-component.html
Sei que tem como fazer com service, mas não queria assim. Tem outra maneira ?