openaire-library/utils/routerHelper.class.ts

35 lines
953 B
TypeScript
Raw Normal View History

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>
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;
}
}