Angular 角度显示已登录用户详细信息

Angular 角度显示已登录用户详细信息,angular,authentication,Angular,Authentication,我有一个带有默认用户的自定义JSON文件。 我想搜索文件以找到匹配的用户输入,然后登录用户。 我一无所获,ps assist? 我的登录码是 onLogin() { this.login = this.loginForm.value; this.em = this.login.email; this.pw = this.login.pword; this.userservice.checkUser(this.em, this.pw) .subscr

我有一个带有默认用户的自定义JSON文件。 我想搜索文件以找到匹配的用户输入,然后登录用户。 我一无所获,ps assist?

我的登录码是

  onLogin() {
    this.login = this.loginForm.value;
    this.em = this.login.email;
    this.pw = this.login.pword;
    this.userservice.checkUser(this.em, this.pw)
      .subscribe(user => this.user = user);
    console.log(this.em, this.pw, this.user);
  }
我的user.service.ts文件如下

  checkUser(email: string, pword: string): Observable<User> {
    return of(USERS.filter((user => user.email === email && user.pword === pword))[0]).pipe(delay(1000));
  } 
checkUser(email:string,pword:string):可观察{
返回(USERS.filter((user=>user.email==email&&user.pword==pword))[0]).pipe(延迟(1000));
} 
HTML文件如下所示

  <mat-card *ngIf="user">
    <mat-card-content>
      Bla bla bla
    </mat-card-content>
  </mat-card>

呜呜呜呜

将检查“user”值的console.log移动到subscribe块中。当前,console.log在可观察对象发出值之前执行

onLogin() {
    this.login = this.loginForm.value;
    this.em = this.login.email;
    this.pw = this.login.pword;
    this.userservice.checkUser(this.em, this.pw).subscribe(user => {
        this.user = user;
        console.log(this.em, this.pw, this.user);
    });
}

塔克斯!那就行了,现在我如何让in4立即在HTML中呈现呢?使用{{user}。查看有关角度插值的教程。