Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87367210
route-reader.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 12, 06:19
Size
1 KB
Mime Type
text/x-java
Expires
Mon, Oct 14, 06:19 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21582762
Attached To
rNIETZSCHEBETAAPP Nietzsche-Beta-App
route-reader.ts
View Options
import { OnInit } from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';
export interface ParamContent {
param: string;
type: string;
debug?: string;
ignore?: boolean;
}
export interface Mapping {
[name: string]: ParamContent;
}
export class RouteReader implements OnInit {
protected mapping: Mapping;
protected routerParams: Params;
constructor(protected router: Router, protected activatedRoute: ActivatedRoute ) { }
ngOnInit() {
this.activatedRoute.queryParams.subscribe(params => {
this.readParams(params)
});
}
protected readParams(params: Params) {
this.routerParams = params;
for(let key of Object.keys(this.mapping)){
if (this.mapping[key]['ignore'] == undefined || !this.mapping[key]['ignore']){
let paramsKey = this.mapping[key]['param'];
if (this.routerParams[paramsKey] != null){
if (this.mapping[key]['type'] == 'number'){
this[key] = Number(this.routerParams[paramsKey])
} else if (this.mapping[key]['type'] == 'boolean'){
this[key] = (this.routerParams[paramsKey] == 'true')
} else if (Array.isArray(this[key]) && !Array.isArray(this.routerParams[paramsKey])) {
this[key] = JSON.parse(this.routerParams[paramsKey])
} else {
this[key] = this.routerParams[paramsKey];
}
if (this.mapping[key]['debug'] != null){
console.log(this.mapping[key]['debug'], this[key]);
}
}
}
}
}
}
Event Timeline
Log In to Comment