0
我不明白为什么结果是“组件之前的指令”。装饰者的运行顺序是什么?
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 –