I'm trying to create a decorator in angular to add a spinner on top of the actual component.
So my actual component is doing any request to the API and I'm putting the decorator on top of the method.
Ideally it should look like this.
export function loaderDecorator() {
return function (target: Object, propertyName: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = async function (...args: any) {
//create a new HttpSpinnerComponent and append it to the target component
try {
const result = await originalMethod.apply(this, args);
//delete HttpSpinner component
return result;
} catch (e) {
//delete HttpSpinner component
}
};
return descriptor;
};
}
But after looking up for a while now I can't find or do anything working. So I was wondering if maybe you knew how i could get access to the angular component factory from my decorator or any other way to put a spinner component on top of my actual loading component (I tried with interceptors and service but can't manage to make it work too)
Angular doesn't support custom decorator on Components.
See this issue