Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
View new-inj-8.ts
export function getRootComponent() {
return inject(AppComponent);
}
View new-inj-7.ts
function createEntityService(store) {
const http = inject(HttpClient);
const loader = inject(NgEntityServiceLoader);
const notifier = inject(NgEntityServiceNotifier);
return new EntityService(store, http, loader, notifier);
}
View new-inj-6.ts
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
export function timespan$() {
const activatedRoute = inject(ActivatedRoute);
return activatedRoute.queryParams.pipe(
pluck('timespan'),
filterNil(),
distinctUntilChanged()
);
}
View new-inj-2.ts
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
export const HTTP = new InjectionToken('', {
providedIn: 'root',
factory() {
return inject(HttpClient);
},
});
@Injectable()
export class FooService {
http = inject(HttpClient);
View env-inject-3.ts
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
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
@NgModule({})
export class AppModule {
constructor(fooService: FooService) {
fooService.initalize();
}
}
@NgModule({})
export class LazyModule {
constructor(fooService: FooService) {
View typed-c-13.ts
interface Profile {
firstName: string;
lastName: string;
address: {
street: string;
city: string
}
}
const profileForm = new FormGroup<ControlsOf<Profile>>({