getParam utils

This commit is contained in:
Adina Țeudan 2022-07-18 16:30:30 +03:00
parent 2ff807aaaa
commit 477e8ea5ae
2 changed files with 10 additions and 3 deletions

View File

@ -77,7 +77,7 @@ export abstract class EntitiesMapService<E extends Entity<I>, I> {
}
replace(entities: E[]) {
/** Return true if files were replaced or false if not **/
/** Return true if entities were replaced or false if not **/
const key = this._pluckPrimaryKey(entities[0]);
const entityIds = entities.map(entity => entity.id);
const existingEntities = this.get(key).filter(entity => entityIds.includes(entity.id));

View File

@ -171,7 +171,14 @@ Array.prototype.filterTruthy = function <T>(this: T[], predicate: (value: T) =>
/**
* Use this in field initialization or in constructor of a service / component
* @param param
* @param route
*/
export function getParam(param: string): string | null {
return inject(ActivatedRoute).snapshot.paramMap.get(param);
export function getParam(param: string, route = inject(ActivatedRoute)): string | null {
if (route.snapshot.paramMap.has(param)) {
return route.snapshot.paramMap.get(param);
}
if (route.parent) {
return getParam(param, route.parent);
}
return null;
}