Skip to content

Instantly share code, notes, and snippets.

View UserGalileo's full-sized avatar

Michele Stieven UserGalileo

View GitHub Profile
@UserGalileo
UserGalileo / angular-injectiontoken.ts
Created August 24, 2021 23:03
Angular InjectionToken
// Injection Token
const APP_CONFIG = new InjectionToken<AppConfig>('Your description!');
const appConfig: AppConfig = { ... }
// The provider's configuration.
// At this point, whoever injects APP_CONFIG gets this object.
// But APP_CONFIG is not a class! How do we grab it?...
@NgModule({
...,
providers: [{ provide: APP_CONFIG, useValue: appConfig }]
@UserGalileo
UserGalileo / cache.interceptor.ts
Created November 14, 2021 19:27
Cache Interceptor
import { Injectable } from '@angular/core';
import {
HttpRequest, HttpResponse,
HttpInterceptor, HttpHandler
} from '@angular/common/http';
import { of } from 'rxjs';
import { startWith, tap } from 'rxjs/operators';
@Injectable()
@UserGalileo
UserGalileo / retry.interceptor.ts
Created November 14, 2021 19:32
Retry Interceptor
import {HttpContextToken, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http';
import {Observable} from 'rxjs';
import {retry, tap} from 'rxjs/operators';
export const RETRY_COUNT = new HttpContextToken(() => 3);
export const ERROR_COUNT = new HttpContextToken(() => 0);
export class RetryInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
@UserGalileo
UserGalileo / fine-day1-academy-angular2-sporco.ts
Created May 6, 2022 20:35
Fine Giorno 1 - Academy Angular 2 (sporco)
import { Component, ViewChild } from '@angular/core';
import {
AbstractControl,
FormArray,
FormBuilder,
FormControl,
FormGroup,
FormGroupDirective, NgForm, ValidationErrors, ValidatorFn,
Validators
} from '@angular/forms';