Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 如何自动关闭角物料中的快餐店_Angular_Angular Material_Angular8 - Fatal编程技术网

Angular 如何自动关闭角物料中的快餐店

Angular 如何自动关闭角物料中的快餐店,angular,angular-material,angular8,Angular,Angular Material,Angular8,我已经实现了一个快餐店,当用户登录时,他/她将收到快餐店的通知,无论登录成功还是失败。在我的实现中,快餐店出现,用户可以单击Discouse,快餐店将消失。如何自动关闭快餐店 onSubmit() { this.isLoggedInError = true; // console.log(this.username); this.userService.login(this.username, this.password) .subscribe((res:

我已经实现了一个快餐店,当用户登录时,他/她将收到快餐店的通知,无论登录成功还是失败。在我的实现中,快餐店出现,用户可以单击Discouse,快餐店将消失。如何自动关闭快餐店

  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;
        }
      );

  }
试试这个


试试这个

你所要做的就是添加一个持续时间:

  this._snackBar.open(message, 'Dismiss', {
  duration: 2000,
});

在这种情况下,它将在2秒后关闭。

您只需添加一个持续时间:

  this._snackBar.open(message, 'Dismiss', {
  duration: 2000,
});

在这种情况下,它将在2秒后关闭。

您可以设置持续时间或设置:

:

一次只能开一家快餐店。如果一个新的snackbar 在前一条消息仍显示时打开,则为旧消息 将自动被解雇


您可以设置的持续时间或设置:

:

一次只能开一家快餐店。如果一个新的snackbar 在前一条消息仍显示时打开,则为旧消息 将自动被解雇


您需要使用持续时间:您可以在此处看到它:


您需要使用持续时间:您可以在此处看到它:

// 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}}
  ]
})