This file contains hidden or 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
private _employeeJsonPath = "assets/employes.json"; | |
const { url, method } = req; | |
if (url.endsWith("/employes") && method === "GET") { | |
req = req.clone({ | |
url: this._employeeJsonPath, | |
}); | |
return next.handle(req).pipe(delay(500)); | |
} |
This file contains hidden or 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
{ | |
"id": "b16ecd2b-596e-4453-a05c-fe10d6f1a4c2", | |
"full_name": "Bard Corkan", | |
"unit": "IT", | |
"emp_avatar": "https://robohash.org/reprehenderitatquelaboriosam.jpg?size=36x36&set=set1" | |
} |
This file contains hidden or 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
const routes: Routes = [ | |
{ path: '', redirectTo: '/home', pathMatch: 'full' }, | |
{ path: 'home', component: HomeComponent }, | |
{ | |
path: 'admin', component: AdminDashboardComponent, | |
canActivate: [AuthGuard], | |
data: { | |
role: 'ROLE_ADMIN' | |
} |
This file contains hidden or 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
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthGuard implements CanActivate, CanActivateChild, CanDeactivate<unknown>, CanLoad { | |
constructor(private authService: AuthService, private router: Router) { } | |
canActivate( | |
next: ActivatedRouteSnapshot, |
This file contains hidden or 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
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class AuthService { | |
isLogin = false; | |
roleAs: string; | |
constructor() { } | |
This file contains hidden or 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
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent implements OnInit { | |
title = 'dynamic-comp-app'; | |
frameworks: FrameworkItem[]; | |
@ViewChild(FrameworkDirective, { static: true }) frameworkHost: FrameworkDirective; | |
constructor(private componentFactoryResolver: ComponentFactoryResolver) { } |
This file contains hidden or 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
loadDynamicComponentsWithIndex(ind: any) { | |
const frameworkItem = this.frameworks[ind]; | |
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(frameworkItem.component); | |
const viewContainerRef = this.frameworkHost.viewContainerRef; | |
viewContainerRef.clear(); | |
const componentRef = viewContainerRef.createComponent(componentFactory); | |
(<FrameworkComponent>componentRef.instance).data = frameworkItem.data; | |
} |
This file contains hidden or 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
<h2>{{data.name}} component selected</h2> | |
<img src="https://upload.wikimedia.org/wikipedia/commons/c/cf/Angular_full_color_logo.svg"> |
This file contains hidden or 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
export class AngularComponent implements OnInit, FrameworkComponent{ | |
@Input('data') data: any; | |
constructor() { } | |
ngOnInit(): void { | |
} | |
} |
This file contains hidden or 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 { Type } from '@angular/core'; | |
export class FrameworkItem { | |
constructor(public component: Type<any>, public data: any) {} | |
} |