forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-params.ts
More file actions
34 lines (27 loc) · 818 Bytes
/
query-params.ts
File metadata and controls
34 lines (27 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { OpaqueToken } from '@angular/core';
export class QueryParams {
data: {[key: string]: any} = {};
constructor(url: string) {
if (url) {
const startIndex = url.indexOf('?');
if (startIndex > -1) {
const queries = url.slice(startIndex + 1).split('&');
for (var i = 0; i < queries.length; i++) {
if (queries[i].indexOf('=') > 0) {
var split = queries[i].split('=');
if (split.length > 1) {
this.data[split[0].toLowerCase()] = split[1].split('#')[0];
}
}
}
}
}
}
get(key: string): any {
return this.data[key.toLowerCase()];
}
}
export const UrlToken = new OpaqueToken('USERURL');
export function setupQueryParams(url: string): QueryParams {
return new QueryParams(url);
}