Is it possible to set default properties for an angular component using a decorator?
For instance, consider this component setup:
@Component({
selector: 'my-component',
standalone: true,
host: { class: 'flx' },
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [MyModule],
template: `<div>My Awesome Component </div;`})
export class MyComponent {}
I commonly use the following 3 attributes in many components:
standalone: true,
host: { class: 'flx' },
changeDetection: ChangeDetectionStrategy.OnPush,
In the past, it was possible to define custom decorators or use a spread operator like this:
const defProps = {
standalone: true,
host: { class: 'flx' },
changeDetection: ChangeDetectionStrategy.OnPush,
}
@Component({
selector: 'my-component',
...defProps,
imports: [MyModule],
template: `<div>My Awesome Component </div;`})
export class MyComponent {}
However, this approach no longer works with the latest Angular versions (16 and 17).
Are there alternative options available? Ideally, I would like to create a component decorator with all my default logic and properties.
PS. While the CLI can create components, that is not a viable solution for me.