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 { Component, OnInit } from '@angular/core'; | |
import { Role } from '../models/role'; | |
@Component({ | |
selector: 'app-profile', | |
templateUrl: './profile.component.html', | |
styleUrls: ['./profile.component.css'] | |
}) | |
export class ProfileComponent { | |
Role = Role; | |
} |
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
<div class="alert alert-success" role="alert"> | |
Profile component! | |
</div> | |
<div class="alert alert-warning" role="alert" *appUser> | |
Content for authorized users only (e.g. display email, send message)! | |
</div> | |
<div class="alert alert-danger" role="alert" *appUserRole="[ Role.Admin ]"> | |
Content for admin users only (e.g. enable/disable user)! | |
</div> |
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 { Component, OnInit } from '@angular/core'; | |
import { Router } from '@angular/router'; | |
import { Role } from '../models/role'; | |
import { AuthService } from '../services/auth.service'; | |
@Component({ | |
selector: 'app-login', | |
templateUrl: './login.component.html', | |
styleUrls: ['./login.component.css'] | |
}) | |
export class LoginComponent { |
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
<div class="alert alert-success" role="alert"> | |
Login component! | |
</div> | |
<button | |
class="btn btn-outline-warning" | |
(click)="login(Role.User)">Login as User</button> | |
<button | |
class="btn btn-outline-danger" | |
(click)="login(Role.Admin)">Login as Admin</button> |
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 { Directive, OnInit, Input } from '@angular/core'; | |
import { TemplateRef, ViewContainerRef } from '@angular/core'; | |
import { AuthService } from '../services/auth.service'; | |
@Directive({ selector: '[appUser]'}) | |
export class UserDirective implements OnInit { | |
constructor( | |
private templateRef: TemplateRef<any>, | |
private authService: AuthService, | |
private viewContainer: ViewContainerRef |
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 { Directive, OnInit, Input } from '@angular/core'; | |
import { TemplateRef, ViewContainerRef } from '@angular/core'; | |
import { AuthService } from '../services/auth.service'; | |
import { Role } from '../models/role'; | |
@Directive({ selector: '[appUserRole]'}) | |
export class UserRoleDirective implements OnInit { | |
constructor( | |
private templateRef: TemplateRef<any>, | |
private authService: AuthService, | |
private viewContainer: ViewContainerRef |
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 { Component, OnInit } from '@angular/core'; | |
import { Router } from '@angular/router'; | |
import { Role } from '../models/role'; | |
import { AuthService } from '../services/auth.service'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent { |
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
<header class="navbar navbar-expand navbar-dark bg-dark"> | |
<ul class="navbar-nav mr-auto"> | |
<li class="nav-item"> | |
<a class="nav-link" [routerLink]="['/']">Home</a> | |
</li> | |
<!-- Authorized only --> | |
<li class="nav-item" *ngIf="isAuthorized"> | |
<a class="nav-link" [routerLink]="['profile']">Profile</a> | |
</li> |
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 { NgModule } from '@angular/core'; | |
import { DashboardComponent } from './dashboard/dashboard.component'; | |
import { RouterModule } from '@angular/router'; | |
import { routes } from './admin-routing.module'; | |
@NgModule({ | |
declarations: [ | |
DashboardComponent | |
], | |
imports: [ | |
RouterModule.forChild(routes) |
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 { Routes } from '@angular/router'; | |
import { DashboardComponent } from './dashboard/dashboard.component'; | |
export const routes: Routes = [ | |
{ path: 'dashboard', component: DashboardComponent } | |
]; |