Como usar o SnackBar no serviço para usar em todos os componentes do Angular 2
Eu tenho uma lanchonete funcional, mas é apenas em cada componente, quero adicioná-la ao meu serviço, então eu vou chamá-la. Esta é a minha amostra no meucomponent.ts
import { MdSnackBar, MdSnackBarRef } from '@angular/material';
...
export class EmployeeListComponent implements OnInit {
public toastRef: MdSnackBarRef<any>;
constructor(private _activatedRoute:ActivatedRoute,private router: Router, private http:PMISHttpService, private toast: MdSnackBar) {
ngOnInit() {
this.notify('test');
}
...
notify (text: string) {
this.toastRef = this.toast.open(text, null);
setTimeout(() => {
this.toastRef.dismiss();
}, 5000);
}
...
}