[英]Angular Display Logged In User Details
I have a custom JSON file with default users.我有一个带有默认用户的自定义 JSON 文件。 I want to search through the file to find matching user inputs and then login the user.
我想搜索文件以查找匹配的用户输入,然后登录用户。 Am getting nothin, ps assist?
什么都没得到,ps 辅助?
My login code is like我的登录代码就像
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);
}
My user.service.ts file is like我的 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));
}
The HTML file is like HTML文件就像
<mat-card *ngIf="user">
<mat-card-content>
Bla bla bla
</mat-card-content>
</mat-card>
Move the console.log where you are checking the value of 'user' into the subscribe block.将您正在检查 'user' 值的 console.log 移动到订阅块中。 Currently, the console.log is executing before the observable emits a value.
目前,console.log 正在 observable 发出值之前执行。
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);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.