我打算如何处理@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);
}
}
然后我有使用它的模块,如:
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
这是处理警报的最佳做法吗?