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';
|
2016-05-07 10:54:44 +03:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class Hash {
|
2016-11-23 02:23:32 +03:00
|
|
|
public value = new BehaviorSubject<string | null>(null);
|
2016-11-24 16:29:29 +03:00
|
|
|
constructor(private location: PlatformLocation) {
|
2016-05-07 10:54:44 +03:00
|
|
|
this.bind();
|
2016-11-24 16:29:29 +03:00
|
|
|
}
|
2016-05-07 10:54:44 +03:00
|
|
|
|
2016-11-24 16:29:29 +03:00
|
|
|
start() {
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|