Skip to content

Instantly share code, notes, and snippets.

View e-oz's full-sized avatar
🕊️

Evgeniy OZ e-oz

🕊️
View GitHub Profile
@e-oz
e-oz / after-reset-center-ng-icon-btn.scss
Created July 21, 2024 11:26
Center the icon inside an Angular Material mat-icon-button
// If you use some "CSS reset" (Tailwind, Bootstrap,
// modern-normalize...), then mat-icon inside the
// Angular Material mat-icon-button will not be centered
// correctly - it will be shifted 2 pixels down.
// Here is the fix:
.mdc-icon-button {
display: flex !important;
flex-flow: row;
align-items: center;
}
@e-oz
e-oz / singleton-only.ts
Last active August 20, 2024 11:38
singletonOnly
import { isDevMode } from '@angular/core';
const singletons = new Set<symbol>();
export function singletonOnly(unique: symbol) {
if (!isDevMode() || typeof window === 'undefined') {
return;
}
if (singletons.has(unique)) {
const msg = unique.toString() + ' MUST BE A SINGLETON! It was instantiated more than once.';
@e-oz
e-oz / control-value-signal.ts
Created February 12, 2025 09:57
Function to get control/form value as a signal
import { computed, type Injector, isSignal, signal, type Signal, untracked } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { AbstractControl } from '@angular/forms';
import { startWith } from 'rxjs';
/**
* Returns a signal that contains the value of a control (or a form).
* @param control
* @param injector
*/