import { Injectable , EventEmitter } from '@angular/core' ; @ Injectable ( ) export class ScrollSpyIndexService { public changes$ : EventEmitter < any > = new EventEmitter ( ) ; private indexes : any = { } ; public getIndex ( key ) { return this . indexes [ key ] ; } public setIndex ( key , index ) { this . indexes [ key ] = index ; this . indexes = this . indexes = Object . assign ( { } , this . indexes ) ; this . changes$ . emit ( { index : key , change : 'set' } ) ; } public deleteIndex ( key ) { delete this . indexes [ key ] ; this . indexes = Object . assign ( { } , this . indexes ) ; this . changes$ . emit ( { index : key , change : 'delete' } ) ; } }