相关疑难解决方法(0)

如何在服务上使用SnackBar在Angular 2中的每个组件中使用

我有一个工作的零食吧,但它只在每个组件上,我想在我的服务上添加它,所以我会打电话给它.这是我的样本component.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);
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)

snackbar angular-material2 angular

12
推荐指数
4
解决办法
9355
查看次数

标签 统计

angular ×1

angular-material2 ×1

snackbar ×1