Skip to content

Instantly share code, notes, and snippets.

View NetanelBasal's full-sized avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
@Injectable({ providedIn: 'root' })
export class FeatureFlagGuard implements CanActivate {
constructor(private userQuery: UserQuery) {
}
canActivate(route: ActivatedRouteSnapshot): boolean {
return this.userQuery.hasFlags(route.data.flags);
}
}
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[autofocus]'
})
export class AutofocusDirective {
constructor(private host: ElementRef) {}
ngAfterViewInit() {
this.host.nativeElement.focus();
{
"todos": {
"entities": { }
},
"cart": {
"entities": { }
},
"session": {
"firstName": ""
}
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,
interface Profile {
firstName: string;
lastName: string;
address: {
street: string;
city: string
}
}
const profileForm = new FormGroup<ControlsOf<Profile>>({
class Observable {
constructor(functionThatThrowsValues) {
this._functionThatThrowsValues = functionThatThrowsValues;
}
subscribe(next, error, complete) {
if (typeof next === "function") {
return this._functionThatThrowsValues({
next,
export class CopyAction extends Action {
getLabel() {
return 'Copy';
}
invoke() {
inject(CopyService).copy();
}
}
@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(
@Directive({
selector: '[range]'
})
export class RangeDirective {
_range: number[];
@Input()
set range( value ) {
this.vcr.clear();
this._range = this.generateRange(value[0], value[1]);
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();