How am I meant to handle alerts in @angular/material?
import { Injectable } from '@angular/core';
import { MdSnackBar, MdSnackBarConfig } from '@angular/material';
@Injectable()
export class AlertsService {
alerts: string[];
constructor(private snackBar: MdSnackBar) {
this.alerts = [];
}
public add(alert: string, action?: string, config?: MdSnackBarConfig) {
this.alerts.push(alert);
// console.warn('AlertsService::alerts =', this.alerts, ';');
this.snackBar.open(alert, action, config);
}
}
Then I have modules which use it, like:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SomeComp1Component } from './some-comp1.component';
import { AlertsService } from '../alerts/alerts.service';
@NgModule({
imports: [
CommonModule
],
declarations: [SomeComp1Component],
exports: [SomeComp1Component],
providers: [AlertsService]
})
export class SomeComp1Module { }
https://github.com/AlecTaylor/material-alerts-ng
Is this a best practice way of handling alerts?
PS: Also asked here: https://stackoverflow.com/q/46242643
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.