Check out this article for some custom decorator inspiration in Angular:
When you comment out the line below, your app will work fine:
constructor.prototype.HelloWord.apply(this, null);
The constructor.prototype is utilized to enable the use of ngOnInit, ngOnChanges, and more.
For example, the code snippet on the page shows how to create a function called NgLog:
import { environment } from "../environments/environment";
export function NgLog() : ClassDecorator {
return function ( constructor : any ) {
if( !environment.production ) {
// You can add/remove events for your needs
const LIFECYCLE_HOOKS = [
'ngOnInit',
'ngOnChanges',
'ngOnDestroy'
];
const component = constructor.name;
LIFECYCLE_HOOKS.forEach(hook => {
const original = constructor.prototype[hook];
constructor.prototype[hook] = function ( ...args ) {
console.log(`%c ${component} - ${hook}`, `color: #4CAF50; font-weight: bold`, ...args);
original && original.apply(this, args);
}
});
}
}
}