Skip to content

Instantly share code, notes, and snippets.

@ShilpaLalwani
Last active April 28, 2020 09:47
Show Gist options
  • Save ShilpaLalwani/d27b0cbbe5c0778ae1926cf4fb1476de to your computer and use it in GitHub Desktop.
Save ShilpaLalwani/d27b0cbbe5c0778ae1926cf4fb1476de to your computer and use it in GitHub Desktop.
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