TypeError:无法读取未定义的属性“过滤器”

时间:2018-03-14 11:45:45

标签: angular angular5

我正在处理错误

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

1 个答案:

答案 0 :(得分:1)

this.users 

未定义,请确保将其分配到组件的其他位置