【发布时间】:2017-12-20 03:55:56
【问题描述】:
是否可以避免破坏 moduleRef 并将其重用于下一个请求(例如在浏览器中工作)?应用程序花费太多时间来重新填充存储(API 请求),所以我找到了缓存它的可能性。
这里是来自ngx-universal/express-engine的源代码
function handleModuleRef(moduleRef: NgModuleRef<{}>, callback: Function, req, res) {
const state = moduleRef.injector.get(PlatformState);
const appRef = moduleRef.injector.get(ApplicationRef);
appRef.tick();
appRef.isStable
.filter((isStable: boolean) => isStable)
.first()
.subscribe((stable) => {
const bootstrap = moduleRef.instance['ngOnBootstrap'];
bootstrap && bootstrap();
if (!res || !res.finished) callback(null, state.renderToString());
moduleRef.destroy(); // remove this line and avoid creating new instance of NgModuleRef every request
});
}
【问题讨论】:
-
如果删除该行会发生什么?
-
它会从第一个请求推送渲染的 html,我也会在第一个请求后保存 moduleRef
标签: node.js angular angular-universal