如何在角料中自动关闭小吃店

Phi*_*tua 1 angular-material angular angular8

我已经实现了一个小吃店,当用户登录时,无论登录成功还是不成功,他/她都会从小吃店收到通知。在我的实现中,小吃店出现,用户可以点击关闭,小吃店就会消失。如何自动关闭小吃店?

  onSubmit() {
    this.isLoggedInError = true;
    // console.log(this.username);
    this.userService.login(this.username, this.password)
      .subscribe((res: any) => {
        // console.log(res);
        this.isLoggedInError = false;
        // console.log("HERE IS THE res")
        // console.log(res.token);
        // this.logInresponsePayload = res;
        // localStorage.setItem('username', res.username);
        localStorage.setItem('userToken', res.token);

        localStorage.setItem('userRoles', res.roles_list);
        // this.router.navigate(['/dashboard']);
        // console.log(res.token);

        // console.log(res.status_code);

        // Add ROLES : Predefine roles  add check 
        if (res.token === null ) {
          const  message = 'Wrong credentials provided!';
          this.snackbar.open(message, 'Dismiss');
          // this.router.navigate(['/']);

          // this.router.navigate(['/dashboard']);
        } else {
          // console.log("print 200")
          const msg = 'Login successfull!';
          this.snackbar.open(msg, 'Dismiss');
          this.router.navigate(['/dashboard']);
        }

        // localStorage.setItem('apps', res.apps);


      },
        (err: HttpErrorResponse) => {
          this.isLoggedInError = false;
        }
      );

  }
Run Code Online (Sandbox Code Playgroud)

pza*_*ger 6

您可以单独设置每个小吃店的持续时间或设置全局配置默认值

// Single snack bar
snackbar.open('Message archived', 'Undo', {
  duration: 3000
});

// Global settings in app.module.ts
@NgModule({
  providers: [
    {provide: MAT_SNACK_BAR_DEFAULT_OPTIONS, useValue: {duration: 2500}}
  ]
})
Run Code Online (Sandbox Code Playgroud)

也很高兴知道

一次只能打开一个小吃店。如果在上一条消息仍在显示时打开新的小吃栏,则旧消息将自动关闭。