Avoid Circular dependencies in Angular

symix0
 
on Mar 17, 2021 06:46 AM
1925 Views

How can I avoid circular dependency on angular

I have a problem with circular dependency on angular that prevents the application from being processed.

export class UserService {
  user$: any;

  constructor(private db: AngularFireDatabase, private authSvr: AuthService) { }
  save(user: firebase.default.User) {
    this.db.object('/users/' + user.uid).update({
      name: user.displayName,
      email: user.email,
    })
  }

  getUser(uid: string) {
    return this.db.object('/users/' + uid)
  }

  get AppUser$(): Observable<firebase.default.UserInfo> {
    return this.authSvr.user$.pipe(
      switchMap((user) => {
        if(user){
          return this.getUser(user.uid).valueChanges
        }
        else{
          return null
        }
    })
    )
  }
}

 

export class AuthService {
  user$ : Observable<firebase.User>;
  constructor(private afAuth: AngularFireAuth , private authSvr : UserService , private route : ActivatedRoute) {
      this.user$ = afAuth.authState;
  }

  login(){
    this.afAuth.signInWithRedirect(new firebase.auth.GoogleAuthProvider())
  }
  logout(){
    this.afAuth.signOut();
  }
  get AppUser$(): Observable<UserInfo> {
    return this.user$.pipe(
      switchMap((user) => {
        if(user){
          return this.authSvr.getUser(user.uid).valueChanges
        }
        else{
          return null
        }
    })
    )
  }
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download