Skip to content

Instantly share code, notes, and snippets.

@vedrax-admin
Last active February 20, 2018 11:08
Show Gist options
  • Save vedrax-admin/9a43224fcda300d7f81b6bc9f38184d2 to your computer and use it in GitHub Desktop.
Save vedrax-admin/9a43224fcda300d7f81b6bc9f38184d2 to your computer and use it in GitHub Desktop.
import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs/BehaviorSubject';
import {convertToParamMap, ParamMap} from '@angular/router';
@Injectable()
export class ActivatedRouteStub {
//Observable that contains a map of the parameters
private subjectParamMap = new BehaviorSubject(convertToParamMap(this.testParamMap));
paramMap = this.subjectParamMap.asObservable();
private _testParamMap: ParamMap;
get testParamMap() {
return this._testParamMap;
}
set testParamMap(params: {}) {
this._testParamMap = convertToParamMap(params);
this.subjectParamMap.next(this._testParamMap);
}
//Observable that contains a map of the query parameters
private subjectQueryParamMap = new BehaviorSubject(convertToParamMap(this.testParamMap));
queryParamMap = this.subjectQueryParamMap.asObservable();
private _testQueryParamMap: ParamMap;
get testQueryParamMap() {
return this._testQueryParamMap;
}
set testQueryParamMap(params: {}) {
this._testQueryParamMap = convertToParamMap(params);
this.subjectQueryParamMap.next(this._testQueryParamMap);
}
get snapshot() {
return {
paramMap: this.testParamMap,
queryParamMap: this.testQueryParamMap
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment