Я пытаюсь создать пользовательский декоратор для патча в функцию ngOnInit на Angular компонентах. Мой декоратор вызывается, и я могу получить ngOnInit из прототипа, но моя функция замены никогда не вызывается в течение жизненного цикла компонента. Кто-нибудь знает, почему мой код не работает?
import {Component, OnInit} from '@angular/core';
function TestDecorator( theClass: Function ) {
console.log( 'decorator called' );
const ngOnInit = theClass.prototype.ngOnInit;
theClass.prototype.ngOnInit = function() {
console.log( 'decorator nginit' );
ngOnInit();
};
}
@TestDecorator
@Component( {
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
} )
export class AppComponent implements OnInit {
title = 'angtest';
constructor() {
console.log( 'component constructed' );
}
ngOnInit(): void {
console.log( 'component nginit' );
}
}