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 { Injectable, InjectionToken, Inject } from '@angular/core'; | |
| export const STORAGE = new InjectionToken<Storage>('Storage', { | |
| providedIn: 'root', | |
| factory: () => localStorage | |
| }); | |
| @Injectable({ | |
| providedIn: 'root', | |
| }) |
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 { Injectable } from '@angular/core'; | |
| @Injectable({ | |
| providedIn: 'root', | |
| }) | |
| export class PersistenceService { | |
| set(key: string, data: any): void { | |
| localStorage.setItem(key, JSON.stringify(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
| { | |
| "/api": { | |
| "target": "http://localhost:3000/api", | |
| "secure": false | |
| } | |
| } |
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 express from 'express'; | |
| import cookieParser from 'cookie-parser'; | |
| import csurf from 'csurf'; | |
| const app = express(); | |
| const csrfProtection = csurf({ | |
| cookie: true, | |
| ignoreMethods: ['GET', 'HEAD', 'OPTIONS'], | |
| }); | |
| app.use(cookieParser()); |
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
| "start": "ng serve --proxy-config proxy.conf.json", |
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 { Component } from '@angular/core'; | |
| import { STORAGE, PersistenceService } from '../services/persistence.service'; | |
| @Component({ | |
| selector: 'app-storage', | |
| templateUrl: './storage.component.html', | |
| providers: [ | |
| PerstistenceService, | |
| { provide: STORAGE, useValue: sessionStorage } | |
| ] |
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 { Component } from '@angular/core'; | |
| @Component({ | |
| selector: 'app-root', | |
| templateUrl: './app.component.html', | |
| styleUrls: ['./app.component.scss'] | |
| }) | |
| export class AppComponent { | |
| title = 'App'; | |
| } |
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
| class Greeter implements Person { | |
| protected person: Person; | |
| constructor(person: Person) { | |
| this.person = person; | |
| } | |
| public greet(): string { | |
| return this.person.greet(); | |
| } |
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 hiGreeterStudent = new Student(); | |
| const helloGreeterStudent = new HelloGreeter(new Student()); | |
| const goodMorningGreeterTeacher = new GoodMorningGreeter(new Teacher()); | |
| hiGreeterStudent.greet(); //"Hi!" | |
| helloGreeterStudent.greet(); //"Hello!" | |
| goodMorningGreeterTeacher.greet(); //"Good morning!" |
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
| interface Person { | |
| greet(): string; | |
| } | |
| class Student implements Person { | |
| public greet(): string { | |
| return 'Hi!'; | |
| } | |
| } |
OlderNewer