Angular 2, Order of Classes

TypeScript itself not sensitive, but this compiled to JS, and JS care about the order
#1

From: https://stackoverflow.com/questions/44049121/has-order-of-exports-in-angular-2-ts-meaning
Author: Gianluca Paris

It's because, as described by Angular component reference (https://angular.io/docs/ts/latest/api/core/index/Component-decorator.html), @Component
is a decorator, which " Marks a class as an Angular component and collects component configuration metadata." So you should put it before the class which is the component. If you put your @Component
decorator just before your Hero
class, you are marking that class as an Angular component, that's not correct.
The Unexpected value 'AppComponent' declared by the module 'AppModule'.
error comes because you declared AppComponent
as a Component
in your AppModule, and without the decorator, the app module does not recognize it anymore. Hope the explanation was helpful.

#2

From: https://stackoverflow.com/questions/37871626/why-the-order-of-classes-matters-in-angular-2-component
Author: Sasxa & Günter Z?chbauer

Decorators (@Component
for example) work on the objects that are right after them. Your code should be:

@Component({...})
class Hero {}
@Component({...})
class AppComponent {}

If you look at the JavaScript example:

app.AppComponent = 
  ng.core.Component({
  }) .Class({
  });

you can see why...
Also, if you're write multiple classes in single file, order matters. JavaScript is executed sequentially, if you ask for something that's not yet defined, you'll get an error.

#3

From: https://stackoverflow.com/questions/34810708/type-declaration-order-in-typescript
Author: vasa_c
TypeScript itself not sensitive, but this compiled to JS.

class A extends B {}
class B {}

In JS:

var A = (function (_super) { /* ... */ })(B);
var B = (function () { /* ... */  })();

B is undefined on line 1.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,655評(píng)論 5 6
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 9,052評(píng)論 0 6
  • 時(shí)間是一道無(wú)形的枷鎖,懲罰著每一個(gè)人。 我們期待著與喜歡的人相遇,期待著與更好的自己相約,為此披荊斬棘,風(fēng)雨兼程。...
    皮皮夏閱讀 233評(píng)論 0 2
  • 夜之降臨黑暗統(tǒng)治世界欲望統(tǒng)治我穿過(guò)酒杯流動(dòng)的誘惑抗拒還是墮落?選擇
    胡三多閱讀 209評(píng)論 0 0
  • laravel valet 502 Bad Gateway 說(shuō)明:mac莫名其妙的就不能訪問(wèn)了。。。。。 原因可能...
    Zeayal閱讀 2,019評(píng)論 2 0

友情鏈接更多精彩內(nèi)容