Skip to content

Instantly share code, notes, and snippets.

View NetanelBasal's full-sized avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
View ffguard.ts
@Injectable({ providedIn: 'root' })
export class FeatureFlagGuard implements CanActivate {
constructor(private userQuery: UserQuery) {
}
canActivate(route: ActivatedRouteSnapshot): boolean {
return this.userQuery.hasFlags(route.data.flags);
}
}
View autofocus.directive.ts
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[autofocus]'
})
export class AutofocusDirective {
constructor(private host: ElementRef) {}
ngAfterViewInit() {
this.host.nativeElement.focus();
View app-state.json
{
"todos": {
"entities": { }
},
"cart": {
"entities": { }
},
"session": {
"firstName": ""
}
View createComponent-5.ts
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,
View typed-c-13.ts
interface Profile {
firstName: string;
lastName: string;
address: {
street: string;
city: string
}
}
const profileForm = new FormGroup<ControlsOf<Profile>>({
View obs7.js
class Observable {
constructor(functionThatThrowsValues) {
this._functionThatThrowsValues = functionThatThrowsValues;
}
subscribe(next, error, complete) {
if (typeof next === "function") {
return this._functionThatThrowsValues({
next,
View run-in-context-2.ts
export class CopyAction extends Action {
getLabel() {
return 'Copy';
}
invoke() {
inject(CopyService).copy();
}
}
View OfflineInterceptor.ts
@Injectable()
export class OfflineInterceptor {
private onlineChanges$ = fromEvent(window, 'online').pipe(mapTo(true));
get isOnline() {
return navigator.onLine;
}
intercept(req, next) {
return next.handle(req).pipe(
View range.ts
@Directive({
selector: '[range]'
})
export class RangeDirective {
_range: number[];
@Input()
set range( value ) {
this.vcr.clear();
this._range = this.generateRange(value[0], value[1]);
View ll-20.ts
import { ComponentFactoryResolver, ComponentRef, Directive, EventEmitter, Input, Type, ViewContainerRef } from '@angular/core';
import { Subscription } from 'rxjs';
@Directive({
selector: '[lazyComp]'
})
export class LazyCompDirective {
private _inputs;
private _outputs;
private subscription = new Subscription();