Skip to content

Instantly share code, notes, and snippets.

View LayZeeDK's full-sized avatar
🇩🇰
Denmark

Lars Gyrup Brink Nielsen LayZeeDK

🇩🇰
Denmark
View GitHub Profile
import { Injectable, Inject } from '@angular/core';
import { configToken } from './config.token';
import { Config } from './config';
@Injectable({
providedIn: 'any', // 👈 Tree-shakable, only bundled if used
})
export class ConfigService {
constructor(@Inject(configToken) private config: Config) {
@LayZeeDK
LayZeeDK / auth.guard.integration.spec.ts
Created September 9, 2020 14:33
AuthGuard: Integrated route guard test suite.
import { Location } from '@angular/common';
import { Component, Injectable, NgModule, NgZone } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { Router, RouterModule, Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
import { AuthGuard } from './auth.guard';
import { AuthService } from './auth.service';
@LayZeeDK
LayZeeDK / auth.guard.spec.ts
Created July 16, 2020 11:32
AuthGuard: Isolated route guard test suite.
import {
ActivatedRouteSnapshot,
Params,
Route,
Router,
RouterStateSnapshot,
UrlSegment,
} from '@angular/router';
import { AuthGuard } from './auth.guard';
@LayZeeDK
LayZeeDK / script.service.ts
Created July 3, 2020 23:46
Angular script service for loading JavaScript script files in the browser, using RxJS.
import { DOCUMENT } from '@angular/common';
import { Inject, Injectable, Renderer2 } from '@angular/core';
import { Observable, ReplaySubject } from 'rxjs';
import { switchMapTo, tap } from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class ScriptService {
private scriptLoaded = new Map<string, Observable<void>>();
@LayZeeDK
LayZeeDK / hero-detail.component.html
Created June 1, 2020 22:08
Hero detail: Integrated routed component test suite.
<div *ngIf="hero">
<h2>
{{hero.name | uppercase}} Details
</h2>
<div>
<span>id:</span>
{{hero.id}}
</div>
@LayZeeDK
LayZeeDK / hero-detail.component.html
Last active November 24, 2020 11:27
Hero detail: Shallow routed component test suite.
<div *ngIf="hero">
<h2>
{{hero.name | uppercase}} Details
</h2>
<div>
<span>id:</span>
{{hero.id}}
</div>
@LayZeeDK
LayZeeDK / dashboard.component.html
Last active February 8, 2023 23:16
Dashboard: Shallow and integrated routing component test suites.
<h3>Top Heroes</h3>
<div class="grid grid-pad">
<a *ngFor="let hero of heroes" class="col-1-4"
routerLink="/detail/{{hero.id}}">
<div class="module hero">
<h4>{{hero.name}}</h4>
</div>
</a>
</div>
@LayZeeDK
LayZeeDK / generate-project.js
Last active April 28, 2022 08:04
Angular CLI workspace tool: Generate project.
const childProcess = require('child_process');
const fs = require('fs');
const yargs = require('yargs');
function addScopeToLibraryProjectName({ name, scope }) {
runCommand('npx json -I -f angular.json '
+ `-e "this.projects['${scope}-${name}'] = this.projects['${name}']"`);
runCommand(`npx json -I -f angular.json -e "delete this.projects['${name}']"`);
}
@LayZeeDK
LayZeeDK / angular-compatibility.md
Created February 19, 2020 21:22
Angular compatibility table - Markdown version
Angular CLI version Angular version Node.js version TypeScript version
- 2.x 6.0.x or later minor version 2.0.x
1.0.6 4.x 6.9.x or later minor version 2.2.x
1.1.3 4.x 6.9.x or later minor version 2.3.x
1.2.7 4.x 6.9.x or later minor version 2.3.x
1.3.2 4.2.x or later minor version 6.9.x or later minor version 2.4.x
1.4.10 4.2.x or later minor version 6.9.x/8.9.x or later minor version 2.4.x
(1.5.6) 5.0.x 6.9.x/8.9.x or later minor version 2.4.x
1.5.6 5.1.x
@LayZeeDK
LayZeeDK / angular-view-engine-to-ivy-transition.csv
Last active July 23, 2021 07:27
The Angular View Engine-to-Ivy transition plan.
Angular version Application engine Library engine Status
Version 9 View Engine View Engine Supported, but not recommended
Version 9 View Engine Ivy Not supported
Version 9 Ivy View Engine Recommended
Version 9 Ivy Ivy Supported, but not recommended
Version 10 View Engine View Engine Supported, but not recommended
Version 10 View Engine Ivy Not supported
Version 10 Ivy View Engine Supported, but not recommended
Version 10 Ivy Ivy Recommended
Version 11 View Engine View Engine Not supported