Skip to content

Instantly share code, notes, and snippets.

View NetanelBasal's full-sized avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
import Select from 'react-select';
import type { ComponentProps } from 'react';
@Component({
standalone: true,
imports: [CommonModule, ReactComponentDirective],
template: `
<h1>Todos page</h1>
<button (click)="changeProps()">Change</button>
<div [reactComponent]="Select" [props]="selectProps"></div>
import { ComponentProps, createElement, ElementType } from 'react';
import { createRoot } from 'react-dom/client';
@Directive({
selector: '[reactComponent]',
standalone: true
})
export class ReactComponentDirective<Comp extends ElementType> {
@Input() reactComponent: Comp;
@Input() props: ComponentProps<Comp>;
{
"todos": {
"entities": { }
},
"cart": {
"entities": { }
},
"session": {
"firstName": ""
}
import { repeat } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class MetricsService {
private http = inject(HttpClient);
getMetrics() {
return this.http.get('https://metrics')
.pipe(
repeat({ delay: 30_000 }),
import { ApplicationRef, createComponent, EnvironmentInjector } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class ToastService {
constructor(
private appRef: ApplicationRef,
private injector: EnvironmentInjector
) { }
@Injectable({ providedIn: 'root' })
export class FeatureFlagGuard implements CanActivate {
constructor(private userQuery: UserQuery) {
}
canActivate(route: ActivatedRouteSnapshot): boolean {
return this.userQuery.hasFlags(route.data.flags);
}
}
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[autofocus]'
})
export class AutofocusDirective {
constructor(private host: ElementRef) {}
ngAfterViewInit() {
this.host.nativeElement.focus();
openDialog<T>(dialogContent: Type<T>) {
const footer = document.createElement('p');
footer.innerText = 'footer';
const dialogContentRef = createComponent(dialogContent, {
environmentInjector: this.injector
})
const dialogRef = createComponent(DialogComponent, {
environmentInjector: this.injector,
interface Profile {
firstName: string;
lastName: string;
address: {
street: string;
city: string
}
}
const profileForm = new FormGroup<ControlsOf<Profile>>({
class Observable {
constructor(functionThatThrowsValues) {
this._functionThatThrowsValues = functionThatThrowsValues;
}
subscribe(next, error, complete) {
if (typeof next === "function") {
return this._functionThatThrowsValues({
next,