Skip to content

Instantly share code, notes, and snippets.

@rosslavery
rosslavery / scroll-tracker.directive.ts
Created May 25, 2017 16:03
Angular service to save / restore scroll position of arbitrary elements on route change
import { AfterViewInit, Directive, ElementRef, NgZone, OnDestroy } from '@angular/core';
import { NavigationEnd, NavigationStart, Router } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
import { ScrollTrackerService } from './scroll-tracker.service';
@Directive({
selector: '[scrollTracker]'
})
export class ScrollTrackerDirective implements AfterViewInit, OnDestroy {
@rosslavery
rosslavery / directives.iconic.js
Created June 6, 2014 19:33
Iconic AngularJS Injection
'use strict';
app.directive('iconic', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
scope.$watch(function() {
// Watch for the number of iconic DOM elements
return element.find('img.iconic').length;