fix base href fn token

This commit is contained in:
Dan Percic 2022-07-25 17:46:17 +03:00
parent c651a6d863
commit 884df60cb8
2 changed files with 9 additions and 10 deletions

View File

@ -56,12 +56,12 @@ export abstract class BaseUserPreferenceService extends GenericService<UserAttri
return this._put(body, `${this._defaultModelPath}/${key}`);
}
private async _save(key: string, value: string): Promise<void> {
protected async _save(key: string, value: string): Promise<void> {
this.userAttributes[key] = [value];
await firstValueFrom(this.savePreferences([value], key));
}
private _getAttribute(key: string, defaultValue = ''): string {
protected _getAttribute(key: string, defaultValue = ''): string {
if (this.userAttributes[key]?.length > 0) {
return this.userAttributes[key][0];
}

View File

@ -19,16 +19,15 @@ export const BASE_HREF = new InjectionToken<string>('BASE_HREF', {
export type BaseHrefFn = (path: string) => string;
export const BASE_HREF_FN = new InjectionToken<BaseHrefFn>('Convert path function', {
factory: () => (path: string) => {
factory: () => {
const baseUrl = inject(BASE_HREF);
if (!baseUrl) {
throw new Error('BASE_HREF is not defined');
}
if (path[0] === '/') {
return baseUrl + path;
}
return (path: string) => {
if (path[0] === '/') {
return baseUrl + path;
}
return baseUrl + '/' + path;
return baseUrl + '/' + path;
};
},
});