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
@LayZeeDK
LayZeeDK / content-child.md
Last active September 16, 2023 21:35
Strict framework-injected properties in Angular components
flowchart TD
    A[ContentChild] --> B;
    B{Is static?} -- No --> C;
    B -- Yes --> D;
    C[Make the query<br>type optional] --> E(Access in<br>ngAfterContentInit<br>or later);
    D(Add assertion<br>in ngOnInit or<br>ngOnChanges) --> F;
    F[Add ! to<br>the query type] --> G(Access in<br>ngOnInit<br>or later)
@LayZeeDK
LayZeeDK / existing resource group with a few changes
Last active April 11, 2022 21:30
az deployment sub what-if
PS> az deployment sub what-if --location westeurope --template-file ./bicep/main.bicep
Note: The result may contain false positive predictions (noise).
You can help us improve the accuracy of the result by opening an issue here: https://aka.ms/WhatIfIssues
Resource and property changes are indicated with these symbols:
+ Create oviders/Microsoft
~ Modify
= Nochange
The deployment will update the following scopes
@LayZeeDK
LayZeeDK / mermaid-flowchart.md
Last active March 2, 2022 21:12
Mermaid Gist
flowchart TD
    A[Deploy to production] --> B{Is it Friday?};
    B -- Yes --> C[Do not deploy!];
    B -- No --> D[Run deploy.sh to deploy!]
    C ----> E[Enjoy your weekend!];
    D ----> E[Enjoy your weekend!];
@LayZeeDK
LayZeeDK / angular-member-ordering.md
Last active September 23, 2025 11:55
Ordering of Angular component class members.

Ordering of Angular component class members

Use the following order of groups to organize Angular components:

  1. Injected dependencies.
  2. Private properties.
  3. Data binding properties.
  4. View and content properties.
  5. UI properties.
  6. Component API properties.
  7. Constructor.
  8. Lifecycle hooks.
@LayZeeDK
LayZeeDK / breadcrumb.integration.spec.ts
Created February 11, 2021 21:06
Tane Piper: Auxiliary route test
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { Component, Injectable, Input, OnDestroy } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { ActivatedRouteSnapshot, NavigationEnd, Route, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Subject } from 'rxjs';
import { filter, map, takeUntil, tap } from 'rxjs/operators';
interface Breadcrumb {
@LayZeeDK
LayZeeDK / my-log-driver\my-log-driver-config.token.ts
Last active March 13, 2021 17:46
Generate Lumberjack log driver with no custom options.
import { inject, InjectionToken } from '@angular/core';
import { LumberjackLogDriverConfig, lumberjackLogDriverConfigToken } from '@ngworker/lumberjack';
export const myLogDriverConfigToken = new InjectionToken<LumberjackLogDriverConfig>('__MY_LOG_DRIVER_CONFIG__', {
factory: () => inject(lumberjackLogDriverConfigToken),
});
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>>();