问题描述
我想使用Angular Universal将字符串值从服务器端(main.server.ts)传递到客户端(任何给定组件)。我找到了TransferState,但是找不到任何示例代码来显示我要执行的操作。
我在main.server.ts中尝试过:
const state = new TransferState();
const CACHE_KEY = makeStateKey('exampleKey');
state.set(CACHE_KEY,'exampleValue');
然后在组件中:
ngOnInit(): void {
const CACHE_KEY = makeStateKey('exampleKey');
console.log(this.state.get(CACHE_KEY,'defaultValue'));
}
但是它只是打印defaultValue。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)