'How to retrive value from firebase in Angular

getpass function is returning nothing and Fpass is undefined as seen in logs. THe value xx is working fine as it perfectly fetches the value from firebase. Iam planning to reuse the getpass() function to pass key and return value from firebase.

export class AppComponent {
  constructor(private db: AngularFireDatabase){}
 

  title = 'App';
  uname: string="";
  pass: string="";
  Fpass:string="";
  
  vali(uname:any,pass:any):void{
    console.log("Username: "+uname+" \nPasssword: "+pass);
    this.Fpass=this.getpass(uname);
    console.log('Fpass: '+this.Fpass);
    if(this.Fpass==pass){
    alert("hi "+uname);
    }
    else
    alert("Wrong !!!");
  }
  getpass(uname:string):any{
    var val;
    this.db.object(`/${uname}/Password/`).valueChanges().subscribe(xx=>{
      console.log(`/${uname}/Password/`+ xx);
      val=xx;
      console.log('val: ',val);
    })
    return val;
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source