2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class RouterHelper {
|
|
|
|
//Use this class function to create queryParams Objects in format {key1:value1} or {key1:value1,key2:value2,key3:value3,...} for multiple parameters
|
|
|
|
constructor(){}
|
|
|
|
// <a [queryParams]="RouterHelper.createQueryParam(filter.filterId,value.id)" routerLinkActive="router-link-active" [routerLink]=baseUrl>Link</a>
|
2023-04-20 19:06:53 +02:00
|
|
|
|
|
|
|
public addQueryParam(key:string,value:string, obj){
|
|
|
|
if(!obj) {
|
|
|
|
obj = {};
|
|
|
|
}
|
|
|
|
obj[key] = value;
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
public createQueryParam(key:string,value:string){
|
|
|
|
var obj ={};
|
|
|
|
obj[key]=value;
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
}
|
|
|
|
public createQueryParamsPaging(keys:string[],values:string[],pageParameter:string,pageValue:number){
|
|
|
|
var obj = this.createQueryParams(keys, values);
|
|
|
|
obj[pageParameter] = ""+pageValue;
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
}
|
|
|
|
public createQueryParams(keys:string[],values:string[]){
|
|
|
|
var obj ={};
|
|
|
|
if(!keys || !values || keys.length != values.length){
|
|
|
|
return obj;
|
|
|
|
}else{
|
|
|
|
for(var i=0; i< keys.length; i++){
|
|
|
|
obj[keys[i]]=values[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
}
|
2020-04-03 18:00:19 +02:00
|
|
|
public createQueryParamsString(keys:string[],values:string[]){
|
|
|
|
let obj ="?";
|
2021-04-18 13:41:55 +02:00
|
|
|
if(!keys || !values || keys.length != values.length || keys.length === 0){
|
2020-04-03 18:00:19 +02:00
|
|
|
return "";
|
|
|
|
}else{
|
|
|
|
for(let i=0; i< keys.length; i++){
|
2021-07-14 13:19:57 +02:00
|
|
|
obj+=(i==0?"":"&")+encodeURIComponent(keys[i])+"="+encodeURIComponent(values[i]);
|
2020-04-03 18:00:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
}
|