I want to get data when input username === responseApi.user from api but my code get all data user from api. Help me to get data tks u Here is a part of my code from service.ts
@Injectable()
export class AuthenticationService {
private apiUrl = "http://5925399f21cf650011fddc7d.mockapi.io/api/users/";
private users: any[]
constructor(
private _router: Router, private _http: Http) { }
getList(): Observable<any[]> {
return this._http.get(this.apiUrl).map((response: Response) => response.json())
}
logout() {
localStorage.removeItem("user");
this._router.navigate(['Login']);
}
login(user) {
this._http.get(this.apiUrl).map((response: Response) => response.json()).subscribe((response: any) => {
this.users = response;
console.log(this.users)
console.log(user.user)
var authenticatedUser = this.users.find(u => u.user === user.user)
var authenticatedUser1 = this.users.find(u => u.password === user.password);
if (authenticatedUser && authenticatedUser1) {
localStorage.setItem('user', authenticatedUser)
this._router.navigate(['Home']);
return true;
}
return false;
}
)
}
via Bi Li
No comments:
Post a Comment