redoc/lib/services/hash.service.ts

32 lines
707 B
TypeScript
Raw Normal View History

2016-05-07 10:54:44 +03:00
'use strict';
2016-10-23 20:18:42 +03:00
import { Injectable } from '@angular/core';
import { PlatformLocation } from '@angular/common';
2016-05-07 10:54:44 +03:00
2016-10-23 20:18:42 +03:00
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { SpecManager } from '../utils/spec-manager';
2016-05-07 10:54:44 +03:00
@Injectable()
export class Hash {
2016-10-23 20:18:42 +03:00
public value = new BehaviorSubject<string>('');
constructor(private specMgr: SpecManager, private location: PlatformLocation) {
2016-05-07 10:54:44 +03:00
this.bind();
2016-10-23 20:18:42 +03:00
this.specMgr.spec.subscribe((spec) => {
if (!spec) return;
setTimeout(() => {
this.value.next(this.hash);
});
});
2016-05-07 10:54:44 +03:00
}
get hash() {
2016-10-23 20:18:42 +03:00
return this.location.hash;
2016-05-07 10:54:44 +03:00
}
bind() {
2016-10-23 20:18:42 +03:00
this.location.onHashChange(() => {
this.value.next(this.hash);
2016-05-07 10:54:44 +03:00
});
}
}