星期四, 3月 30, 2017

[Angular] App 是如何開始載入與運行的(進入點)

Angular (2.x/4.x) 入口:main.ts → 透過 bootstrapModule 把 AppModule 綁進來

app.module.ts 裡頭透過 bootstrap array,告訴 angular 有多少 components 要被用到。由於 index.html 裡頭不會引入其他 html 或 css 等資訊,那 angular 是如何知道去哪裡找這些資源?就是透過這個 NgModule 的 declarations,告訴 angular 我們需要用到哪些 components。

其中 app.component.ts 就會定義 Component 的 selector 名稱、html template、css 等內容