2017-04-11 92 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

相关问题