Last active
January 30, 2019 19:43
-
-
Save ziuniecki/8a8029541fcff098188a1a44eb8228a2 to your computer and use it in GitHub Desktop.
Angular component custom decorator boilerplate with parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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