Skip to content

Instantly share code, notes, and snippets.

@ziuniecki
Last active January 30, 2019 19:43
Show Gist options
  • Save ziuniecki/8a8029541fcff098188a1a44eb8228a2 to your computer and use it in GitHub Desktop.
Save ziuniecki/8a8029541fcff098188a1a44eb8228a2 to your computer and use it in GitHub Desktop.
Angular component custom decorator boilerplate with parameters
import {OnInit, Type} from '@angular/core';
/**
* Decorator with params for Angular components.
* InterfaceName is name of interface that declare required fields, which component should have.
* How to use:
* `
@DecoratorName(params)
@Component({
selector: 'app-example',
templateUrl: './app-example.component.html',
styleUrls: ['./app-example.component.scss'],
})
export class ExampleComponent implements OnInit, InterfaceName {
}
`
*/
export function DecoratorName(value) {
return function <T extends (InterfaceName)>(baseClass: Type<T>) {
class Component extends (baseClass as Type<InterfaceName>) implements OnInit {
public ngOnInit() {
super.ngOnInit();
}
}
return Component as Type<any>;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment