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
const appRoutes: Routes = [ | |
{ | |
path: 'dashboard', | |
component: DashboardPageComponent, | |
canActivate: [NeedAuthGuard] // <---- connected Route with guard | |
}, | |
{ | |
path: 'login', | |
component: LoginPageComponent | |
}, |
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 {CanActivate, Router} from '@angular/router'; | |
import {Injectable} from '@angular/core'; | |
import {CustomerService} from './customer.service'; | |
import {ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router/src/router_state'; | |
@Injectable() | |
export class NeedAuthGuard implements CanActivate { | |
constructor(private customerService: CustomerService, private router: Router) { | |
} |
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} from '@angular/core'; | |
const TOKEN = 'TOKEN'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class CustomerService { | |
setToken(token: string): void { |
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} from '@angular/core'; | |
import {HttpClient} from '@angular/common/http'; | |
import {Observable} from 'rxjs'; | |
import {LoginResultModel} from './model/LoginResultModel' | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class ApiService { |
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} from '@angular/core'; | |
import {ApiService} from '../api.service'; | |
import {CustomerService} from '../customer.service'; | |
import {Router} from '@angular/router'; | |
@Component({ | |
selector: 'app-login-page', | |
templateUrl: './login-page.component.html', | |
styleUrls: ['./login-page.component.css'] | |
}) |
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="card mt-5" style="margin:auto;width: 600px;"> | |
<div class="card-body"> | |
<h5 class="card-title">Login</h5> | |
<div class="form-group"> | |
<label for="email">Email</label> | |
<input type="text" class="form-control" id="email" placeholder="Email Address" [(ngModel)]="email"> | |
</div> | |
<div class="form-group"> | |
<label for="email">Password</label> | |
<input type="password" class="form-control" id="password" placeholder="Password" [(ngModel)]="password"> |
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
<template> | |
<div> | |
Hello World | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'welcome' | |
} |
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
@Component({ | |
selector: 'welcome', | |
template: '<div>Hello World</div>', | |
styleUrls: ['./welcome.component.css'] | |
}) | |
export class WelcomeComponent { | |
} |
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
class Welcome extends React.Component { | |
render() { | |
return <div>Hello World!</div>; | |
} | |
} |
NewerOlder