ng g m
--name=onboarding
--module=app-routing
--route=onboarding
--routing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
const LOCALE = navigator.languages | |
? navigator.languages[0] | |
: (navigator.language || (navigator as any).userLanguage); | |
type Formats = 'short' | 'medium' | 'shortDate'; | |
const predefinedFormats: Record<Formats, Intl.DateTimeFormatOptions> = { | |
short: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"todos": { | |
"entities": { } | |
}, | |
"cart": { | |
"entities": { } | |
}, | |
"session": { | |
"firstName": "" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApplicationRef, createComponent, EnvironmentInjector } from '@angular/core'; | |
@Injectable({ providedIn: 'root' }) | |
export class ToastService { | |
constructor( | |
private appRef: ApplicationRef, | |
private injector: EnvironmentInjector | |
) { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Injectable({ providedIn: 'root' }) | |
export class FeatureFlagGuard implements CanActivate { | |
constructor(private userQuery: UserQuery) { | |
} | |
canActivate(route: ActivatedRouteSnapshot): boolean { | |
return this.userQuery.hasFlags(route.data.flags); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, ElementRef } from '@angular/core'; | |
@Directive({ | |
selector: '[autofocus]' | |
}) | |
export class AutofocusDirective { | |
constructor(private host: ElementRef) {} | |
ngAfterViewInit() { | |
this.host.nativeElement.focus(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
NewerOlder