Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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 ng snotify登录后不显示烤面包机_Angular_Snotify - Fatal编程技术网

Angular ng snotify登录后不显示烤面包机

Angular ng snotify登录后不显示烤面包机,angular,snotify,Angular,Snotify,我正在angular 11中构建一个示例应用程序,其中我实现了ng snotify,以生成用于空登录(无凭据)、错误登录和有效登录的toaster。ng snotify烤面包机对无效凭据正常工作,但对有效登录凭据无效,对于空凭据,有时会同时显示空凭据烤面包机和登录成功烤面包机,这在技术上是不正确的。 下面是代码文件,以便更好地理解 login.component.ts // @ts-ignore import { Component, OnInit } from '@angular/core';

我正在angular 11中构建一个示例应用程序,其中我实现了ng snotify,以生成用于空登录(无凭据)、错误登录和有效登录的toaster。ng snotify烤面包机对无效凭据正常工作,但对有效登录凭据无效,对于空凭据,有时会同时显示空凭据烤面包机和登录成功烤面包机,这在技术上是不正确的。 下面是代码文件,以便更好地理解

login.component.ts

// @ts-ignore
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { CookieService } from 'ngx-cookie-service';
import { AuthService } from '../../services/auth.service';
import { ToastrService } from "ngx-toastr";
import { NgxSpinnerService } from 'ngx-spinner';
import { SnotifyService } from "ng-snotify";

/*import {userInfo} from "os";*/

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit {
  /*Properties*/
  loading: boolean = false;
  action: string = '';
  private index: number = 0;

  constructor(public authService: AuthService,
    private router: Router,
    private cookieService: CookieService,
    private toastr: ToastrService,
    private spinner: NgxSpinnerService,
    private snotifyService: SnotifyService) {
  }

  ngOnInit() {

  }

  signIn($event: any, email: string, pass: string): void {
    this.loading = true;
    const data = {
      userName: email,
      password: pass
    };

    if (data.userName === '' || data.password === '') {
      this.loading = false;

      this.snotifyService.warning('Username & Password cannot be empty', '', {
        timeout: 7000,
        showProgressBar: false,
        closeOnClick: false,
        pauseOnHover: true
      });

      $event.preventDefault();
    } else {
      this.authService.logIn(data).subscribe(response => {
        if (response.isValid == true) {
          this.cookieService.set('username', response.username);
          this.cookieService.set('password', response.username);
          this.cookieService.set('userId', response.id);
          this.cookieService.set('isLoggedIn', response.isValid);


          this.snotifyService.success('Logged in successfully!', '', {
            timeout: 7000,
            showProgressBar: false,
            closeOnClick: false,
            pauseOnHover: true
          });


          this.router.navigateByUrl('/db');
          this.loading = false;
        } else {
          this.loading = false;

          this.snotifyService.error('Invalid Username or Password !', '', {
            timeout: 7000,
            showProgressBar: false,
            closeOnClick: false,
            pauseOnHover: true
          });
        }
      }, error => {
        this.loading = false;
      });
      $event.preventDefault();
    }
  }
}


有什么解决方案吗?

您导航到另一个页面,因此基本上看不到成功通知(它只是在重定向后快速发生)


您可以通过订阅另一个页面或在/db启动时(当它登录-重定向时,以及在登录组件启动后(使用afterViewInit)来实现您可以发出通知。

Medinios:我必须在登录组件或登录后显示的组件中实现afterView?在登录后显示的组件中实现afterView。Medinios:谢谢兄弟,它正在工作,但有一点是,有时它会在登录后显示两个烤面包机“登录成功!”。有什么解决方案吗这是吗?是的,你必须在登录后弹出它,你可以使用多种解决方案-一种解决方案带有一个标志,会说“嗨,我刚刚登录”,当它发生时,发送一个通知(可能使用本地存储(在通知/主题后删除),顺便说一句,如果答案是绿色v:)梅迪尼奥斯:你能举个例子吗?
 this.router.navigateByUrl('/db');