I'm learning Observables and trying to implement a service for login validation. Dummy data is like this
export class Users {
public users: IUser[] = [];
constructor() {
this.users = [
new IUser({ username: "protagonist", password: "hello123" }),
new IUser({ username: "rono67", password: "!@vioped" }),
new IUser({ username: "donaldtrump", password: "melenia@34" })
];
}
and structure of IUser is like this.
export class IUser {
usename:string;
password:string;
}
I'm passing the entered username and password to the service class and I want to have an observable call which traverse through the dummy data and if it finds the matching credentials, it shall return it. I do not want to make any HTTP call. Method is something like this-
validLogin(accountInfo: IUser): Observable<IUser> {
return ---------
.map((user:IUser) => user.filter((user:IUser) => user.usernanme == accountInfo.username && user.password == accountInfo.password);
}
I'm not sure what piece of code needs to be written in the place of return ------. All of the results which I got in the web are implementing "return this.http.post"
Is it possible to apply RxJs on mock data? Kindly suggest.