Last active
April 28, 2020 09:47
-
-
Save ShilpaLalwani/d27b0cbbe5c0778ae1926cf4fb1476de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable,ComponentFactoryResolver, ViewContainerRef } from '@angular/core'; | |
import { BehaviorSubject } from 'rxjs'; | |
@Injectable({ providedIn: 'root' }) | |
export class ProfileService { | |
private isLoggedIn = new BehaviorSubject(false); | |
isLoggedIn$ = this.isLoggedIn.asObservable(); | |
constructor(private cfr: ComponentFactoryResolver) {} | |
login() { | |
this.isLoggedIn.next(true); | |
} | |
logout() { | |
this.isLoggedIn.next(false); | |
} | |
async loadComponent(vcr: ViewContainerRef, isLoggedIn: boolean) { | |
const { GuestCardComponent } = await import('./guest-card/guest-card.component'); | |
const { UserCardComponent } = await import('./user-card/user-card.component'); | |
vcr.clear(); | |
let component : any = isLoggedIn ? UserCardComponent : GuestCardComponent; | |
return vcr.createComponent( | |
this.cfr.resolveComponentFactory(component)) | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment