なぜ結果が「コンポーネントの前の命令」であるのかわかりません。デコレータの実行順序とは何ですか?
function Component(component) {
console.log('selector: ' + component.selector);
console.log('template: ' + component.template);
console.log('component init');
return (target: any) => {
console.log('component call');
return target;
}
}
function Directive() {
console.log('directive init');
return (target: any) => {
console.log('directive call');
return target;
}
}
@Component({selector: 'person',template: 'person.html'})
@Directive()
class Person {}
let p = new Person();
出力:
selector: person
template: person.html
component init
directive init
directive call
component call
はcomponent call
はdirective call
前にすべきではありませんか?
は、なぜあなたはそれを思いますか?デコレータはその下のものに適用されるため、「内側に」適用されます。 – jonrsharpe
どこからでも読むことができます。デコレータは左から右へ、上から下へ – Hao
これは、マニュアルhttps://www.typescriptlang.org/docs/handbook/decorators.html#decorator-compositionで直接説明しています。 –