我正在处理错误
的 angular 5 和 onSubmit()错误类型错误:无法读取未定义
的属性“过滤器”
以下是login.component.ts
文件的onSubmit() {
this.valid = true;
const name = this.login.userName;
sessionStorage.setItem('username', this.login.userName);
const password = this.login.password;
console.log(name);
const user = this.users.filter(currUser => currUser.userName === name && currUser.password === password)[0]; // here I am getting an error!
if (user) {
this.isLoggedIn = 'true';
sessionStorage.setItem('isLoggedIn', this.isLoggedIn);
// this.router.navigate(['/products']);
} else {
this.isLoggedIn = 'false';
sessionStorage.setItem('isLoggedIn', this.isLoggedIn);
this.valid = false;
}
}
:
app.UseAuthentication();
app.UseMvc();
答案 0 :(得分:1)
this.users
未定义,请确保将其分配到组件的其他位置