I want to access the content of a variable I filled with an array of an firebase subscription, my problem is I cant/dont know how to access/get the value which I created inside the subscription. it feels like I cant use the created value outsite of the subcription(from angularfirestore)
import { Component, OnInit } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { AuthService } from "../../services/auth.service";
@Component({
selector: 'app-sign-in',
templateUrl: './sign-in.component.html',
styleUrls: ['./sign-in.component.scss']
})
export class SignInComponent implements OnInit {
email = new FormControl('', [Validators.required, Validators.email]);
users2: any[] = [];
constructor(public authService: AuthService) {
}
ngOnInit(): void {
this.getUsers2();
console.log("show-res??",this.users2) //not showing the filled array only an empty one
}
getUsers2(){
this.authService
.getCollection2("users")
//.subscribe(res =>(console.log("show-res",res)))//her shows the res i need
.subscribe((res: any[])=>{(this.users2 =res)})
}
}
//auth.service.ts file
...
getCollection2(collection: string) {
return this.afs.collection(collection).valueChanges();
}
...