SAP Spartacus 服务器端 nodejs 应用里渲染 Angular Component 的一个例子
觸發方式:將下列 url 粘貼到瀏覽器地址欄里,回車:
http://localhost:4000/Open-Catalogue/Cameras/Hand-held-Camcorders/c/584
最終會觸發一系列遞歸的函數調用:
- refreshView
- refreshChildComponents
- refreshComponent
- refreshEmbeddedViews
在 refreshView 里,會調用 Component 的一系列 hook,比如 ngOnInit:
注意
下列這些代碼執行,都是在服務器端,nodejs 服務器運行環境下執行的!
在服務器端運行環境下,window 等全局變量不可用。
ComponentWrapperDirective 指令的 ngOnInit,最終會調用 this.launchComponent 方法,創建 Component 實例:
通過執行模板函數的方式,執行服務器端渲染,下圖就是具體的模板生成邏輯。
其中,訪問 url 后看到的業務數據,即 category code 為 584 對應的產品數據,都是通過服務器端調用 Commerce API,從 Commerce Cloud 后臺讀取的:
http://localhost:4000/Open-Catalogue/Cameras/Hand-held-Camcorders/c/584
this.search 執行的參數:
更多Jerry的原創文章,盡在:“汪子熙”:
總結
以上是生活随笔為你收集整理的SAP Spartacus 服务器端 nodejs 应用里渲染 Angular Component 的一个例子的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SAP Spartacus 服务器端渲染
- 下一篇: SAP Spartacus 服务器端渲染