Angular 應用 bootstrapModule 映射的 app Component 的初始化邏輯

main.js 裏指定的 AppModule 作爲 bootstrap module:

該 module 包含的 bootstrap Component 爲 AppComponent:

如果遇到 SAP Spartacus 白屏問題,首先檢查這個 Component 的幾個 hook 是否正常工作:


記住這些關鍵點,以後好調試:


可以看到,在 OnInit 執行內部,app-root 下面的 cx-storefront 就已經能看到了。

而在我的白屏 case 裏,只能看到:

<app-root></app-root>

在 bootstrap 方法第一行設置斷點:


此時 app-root 節點下面的子節點尚未生成。設置一個斷點:


最後發現,是 componentFactory.create 方法裏,觸發的 dom 節點的生成以及視圖的繪製工作:

更多Jerry的原創文章,盡在:"汪子熙":


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章