I'm making a login app in angular 10 and now I need to somehow access the data, but I'm not sure how.
This is where I get my data. The method "getUsers" gets all the data.
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { LoginModel } from '../models/login.model';
import { tap } from 'rxjs/operators';
@Injectable()
export class LoginService {
private url = 'api/user';
// tslint:disable-next-line: variable-name
private _users$ = new BehaviorSubject<LoginModel[]>([]);
get users$(): Observable<LoginModel[]> { return this._users$.asObservable(); }
constructor(private http: HttpClient) { }
getUsers(): Observable<LoginModel[]> {
return this.http.get<LoginModel[]>(this.url)
.pipe(
tap(data => this._users$.next(data))
);
}
}
This is the model I use:
export interface LoginModel {
userID: string;
wachtwoord: string;
admin: boolean;
}
Now I want to access specific data from this in my login component, like for example the userID. In my logincomponent I imported the LoginService (the first code) so I can use the "getUsers" method (which returns an array), but how do I get the specific data from the array? Thanks in advance.
mapoperator. Also, can you include some sample data to illustrate what exactly you want to fetch from it.