Your solution is to create a snackbar
component.
Without seeing your code, I'm guessing you have roughly something like this:
this.snackBar.open(this.sampleStringErrorMsg, null, {
verticalPosition: 'top'
});
As far as I'm aware, there's no way to achieve what you want by doing like the above.
- Create a component. I'll call it
ErrorSnackBarComponent
.
On the html
add the contents of your error message. It will look like something like this:
<div>
<p>
<span>The sample is not valid:</span>
<br/>
<span>The key and key value are required in the sample.</span>
<br/>
<span>The delimiter must be entered when the sample contains several key-value pairs.</span>
<br/>
<span>The delimiter must not be equal to the key or key value.</span>
</p>
</div>
Make sure the ErrorSnackBarComponent
is referenced in the app.module.ts
under:
- declarations
- entryComponents
Use your recently created snackbar
component:
this.snackBar.openFromComponent(ErrorSnackBarComponent, {
verticalPosition: 'top'
});
Extra step
If you want to pass data to the ErrorSnackBarComponent
, change your snackbar component's constructor to this:
constructor(@Inject(MAT_SNACK_BAR_DATA) public data: any) { }
and instead of 3., use this:
this.snackBar.openFromComponent(ErrorSnackBarComponent, {
verticalPosition: 'top',
data: <YOUR_DATA_HERE>
});
and you should be able to use data
from the ErrorSnackBarComponent
and display your error message alongside with any other details such as properties.
Here is the documentation for snackbar
for your reference.