我發現這個職位:https://github.com/angular/universal/issues/272其中user @ gdi2290解釋如何添加functionalty如何存儲令牌在服務器端[角通用]
但我在我的代碼得到錯誤:
/home/master/Documents/rs-dash/dist/server/server.bundle.js:317 throw new Error("Module build failed: Error: /home/master/Documents/rs-dash/src/app/app.node.module.ts (97,48): Property 'injector' does not exist on type 'ApplicationRef'.)\n/home/master/Documents/rs-dash/src/app/app.node.module.ts (97,61): Cannot find name 'YourServiceWithState'.)\n at _checkDiagnostics (/home/master/Documents/universal-cli/packages/@ngtools/webpack/src/loader.ts:115:15)\n at /home/master/Documents/universal-cli/packages/@ngtools/webpack/src/loader.ts:140:17"); ^
我
constructor(public appRef: ApplicationRef) {
}
// lives in your node main module
universalDoDehydrate(universalCache) {
var yourServiceWithState = this.appRef.injector.get(YourServiceWithState)
var key = 'yourServiceWithState._state'
universalCache[key] = yourServiceWithState._state.justOneProp
}
和瀏覽器模塊:
constructor(public appRef: ApplicationRef) {
// lives in your browser main module
var key = 'yourServiceWithState._state'
if (UNIVERSAL_CACHE[key]) {
localStorage[key] = UNIVERSAL_CACHE[key]
}
}
01在節點模塊添加
任何人都知道是什麼問題,我使用universal-cli
?
謝謝,您能否展示在通用cli和用法上進行集成的步驟? – Vladimir
我想這周我會發布一篇關於它的文章,仍然忙於編寫這些回購的文檔。 –
這將是偉大的,謝謝!通用的cli實施將非常有用。 – Vladimir