Skip to content

Instantly share code, notes, and snippets.

View NetanelBasal's full-sized avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
import {
provideHttpClient,
withJsonpSupport,
withXsrfConfiguration
} from '@angular/common/http';
import { bootstrapApplication } from '@angular/platform-browser';
bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(
const userControl = this.fb.control('', Validators.required);
const groupControl = this.fb.control('', Validators.required);
const $case = this.assignee?.get('$case');
$case?.valueChanges.pipe(startWith($case.value)).subscribe(($case) => {
clearOneOf(this.assignee);
this.assignee.addControl(
$case,
$case === 'userId' ? userControl : groupControl
@Component({
template: `
<form [formGroup]="form">
<ng-container formGroupName="assignee">
<div>
<input
type="radio"
name="$case"
formControlName="$case"
value="userId"
@Component({
template: `
<form #f="ngForm">
<ng-container ngModelGroup="assignee">
<div>
<input
type="radio"
name="$case"
[ngModel]="assigneeCase"
value="userId"
interface Task {
name: string;
assignee:
| { $case: 'userId'; userId: string }
| { $case: 'userGroupId'; userGroupId: string };
}
// users.routes.ts
import { SvgIconRegistry } from '@ngneat/svg-icon';
import { addGroupIcon, removeGroupIcon } from '@app/svg';
const ICONS_INIT = attachInitEffect(() => {
inject(SvgIconRegistry).register([
addGroupIcon,
removeGroupIcon
])
})
bootstrapApplication(AppComponent, {
providers: [
OFFLINE_INIT
]
})
export const OFFLINE_INIT = attachInitEffect(() => {
const toast = inject(ToastService);
const window = inject(WINDOW);
window.addEventListener('offline', () => {
toast.warning('There is no internet connection', {
duration: 10_000,
})
})
})
import { ENVIRONMENT_INITIALIZER, Provider } from '@angular/core';
export function attachInitEffect(fn: VoidFunction): Provider {
return {
multi: true,
provide: ENVIRONMENT_INITIALIZER,
useValue: fn,
};
}
AppComponent.ɵfac = function AppComponent_Factory(t) {
return new (t || AppComponent)(
_angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵɵdirectiveInject"](FOO),
_angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵɵdirectiveInject"](BAR, 8),
_angular_core__WEBPACK_IMPORTED_MODULE_0__["ɵɵdirectiveInject"](
_angular_common_http__WEBPACK_IMPORTED_MODULE_1__.HttpClient
),
...
);
};