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 –