왜 결과가 "구성 요소 앞의 지시문"인지 이해할 수 없습니다.데코레이터 실행 순서는 무엇입니까?
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에서 다루고 있습니다. –