View new-inj-6.ts
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
export function untilDestroyed() { | |
const subject = new Subject<void>(); | |
const viewRef = inject(ChangeDetectorRef) as ViewRef; | |
viewRef.onDestroy(() => { | |
subject.next(); | |
subject.complete() | |
}); |
View new-inj-4.ts
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
export function timespan$() { | |
const activatedRoute = inject(ActivatedRoute); | |
return activatedRoute.queryParams.pipe( | |
pluck('timespan'), | |
filterNil(), | |
distinctUntilChanged() | |
); | |
} |
View new-inj-2.ts
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 { inject } from '@angular/core'; | |
import { ActivatedRoute } from '@angular/router'; | |
export function getRouteParam(key: string) { | |
return inject(ActivatedRoute).snapshot.params[key]; | |
} |
View new-inj-1.ts
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
export const HTTP = new InjectionToken('', { | |
providedIn: 'root', | |
factory() { | |
return inject(HttpClient); | |
}, | |
}); | |
@Injectable() | |
export class FooService { | |
http = inject(HttpClient); |
View env-inject-3.ts
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
export const todosRoutes: Routes = [ | |
{ | |
path: '', | |
loadComponent: () => | |
import('./todos-page.component').then((m) => m.TodosPageComponent), | |
providers: [ | |
{ | |
provide: ENVIRONMENT_INITIALIZER, | |
multi: true, | |
useValue() { |
View env-inject-2.ts
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 { ENVIRONMENT_INITIALIZER, inject } from '@angular/core'; | |
import { bootstrapApplication } from '@angular/platform-browser'; | |
bootstrapApplication(AppComponent, { | |
providers: [ | |
{ | |
provide: ENVIRONMENT_INITIALIZER, | |
multi: true, | |
useValue() { | |
inject(FooService).init() |
View env-injec-1.ts
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
@NgModule({}) | |
export class AppModule { | |
constructor(fooService: FooService) { | |
fooService.initalize(); | |
} | |
} | |
@NgModule({}) | |
export class LazyModule { | |
constructor(fooService: FooService) { |
View typed-c-13.ts
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
interface Profile { | |
firstName: string; | |
lastName: string; | |
address: { | |
street: string; | |
city: string | |
} | |
} | |
const profileForm = new FormGroup<ControlsOf<Profile>>({ |
View typed-c-12.ts
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
const profileForm = new FormGroup({ | |
firstName: new UntypedFormControl(''), | |
lastName: new UntypedFormControl(''), | |
address: new UntypedFormGroup({ | |
street: new UntypedFormControl(''), | |
city: new UntypedFormControl('') | |
}) | |
}); |
View typed-c-11.ts
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
const names = new UntypedFormArray([]); |