Skip to content

Instantly share code, notes, and snippets.

@CharlieGreenman
Created August 29, 2019 18:23
Show Gist options
  • Save CharlieGreenman/2cb9f75457da45a63d2b61333e5402d1 to your computer and use it in GitHub Desktop.
Save CharlieGreenman/2cb9f75457da45a63d2b61333e5402d1 to your computer and use it in GitHub Desktop.
Directive for preloading Angular Modules
import { Directive, ElementRef, HostListener } from '@angular/core';
import { OnDemandPreloadService } from '@razroo/common/services';
@Directive({
selector: '[razrooPreload]'
})
export class PreloadDirective {
constructor(private elementRef : ElementRef,
private onDemandPreloadService: OnDemandPreloadService) {}
@HostListener('mouseenter')
onMouseEnter() {
const pathName = this.elementRef.nativeElement.attributes.routerlink.value;
this.onDemandPreloadService.startPreload(pathName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment