2017-04-11 94 views
1

我發現這個職位: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

回答

0

我有問題,並制定了它的高速緩存&服務器端解決方案(高速緩存操作4個單獨的包上都服務器和瀏覽器平臺)。

檢查在ng-seed/universal實施。一切都通過@Cached(...)修飾器處理你想要緩存的method/loader/etc。此外,還有使用使用緩存API高速緩存方法(hasgetset)的可能性。

這裏有您需要使用的軟件包,服務器端緩存:

+0

謝謝,您能否展示在通用cli和用法上進行集成的步驟? – Vladimir

+0

我想這周我會發布一篇關於它的文章,仍然忙於編寫這些回購的文檔。 –

+0

這將是偉大的,謝謝!通用的cli實施將非常有用。 – Vladimir

相關問題