我发现这个职位: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