Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Netanel Basal NetanelBasal

🎯
Focusing
View GitHub Profile
View relative-guard-3.ts
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, createUrlTreeFromSnapshot } from '@angular/router';
@Injectable({ providedIn: 'root' })
export class MyGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot) {
if(checkData(route)) {
return createUrlTreeFromSnapshot(route, ['../sibling']);
}
View relative-guard-1.ts
@Injectable({ providedIn: 'root' })
export class MyGuard implements CanActivate {
constructor(private router: Router, private route: ActivatedRoute) { }
canActivate(route: ActivatedRouteSnapshot) {
if(checkData(route)) {
this.router.navigate(['../sibling'], { relativeTo: this.route });
return false;
}
View can-match-1.ts
@Injectable({ providedIn: 'root' })
class CanMatchNewTodos implements CanMatch {
constructor(private ff: FeatureFlagsService) { }
canMatch() {
return this.ff.hasPermission('todos-v2');
}
}
View copy-55.directive.ts
import { fakeAsync, tick } from '@angular/core/testing';
import { HotToastService } from '@ngneat/hot-toast';
import { createDirectiveFactory } from '@ngneat/spectator';
import { CopyDirective } from './copy.directive';
describe('CopyDirective', () => {
const createDirective = createDirectiveFactory({
directive: CopyDirective,
mocks: [HotToastService]
});
View copy-44.directive.ts
import { Directive, ElementRef, Input, NgZone } from '@angular/core';
import { HotToastService } from '@ngneat/hot-toast';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { fromEvent, switchMap } from 'rxjs';
@UntilDestroy()
@Directive({
selector: '[copy]'
})
export class CopyDirective {
View copy-33.directive.ts
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
@UntilDestroy()
@Directive({
selector: '[copy]'
})
export class CopyDirective {
@Input() copy: string;
constructor(
View copy-22.directive.ts
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
@UntilDestroy()
@Directive({
selector: '[copy]'
})
export class CopyDirective {
@Input() copy: string;
constructor(private host: ElementRef<HTMLElement>) {}
View copy-11.html
<button copy="Clicking this button copies this text to the clipboard">
Copy
</button>
<button [copy]="fooText">
Copy
</button>
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);
}