我正在使用以下代码在运行时从资产文件夹中加载json
文件:
initializeApp = () =>
new Promise(async resolve => {
this.settings await this.http.get(`/assets/file.json`).toPromise();
resolve();
});
使用ng serve
编译angular应用程序时,此代码可以正常工作。但是,我也想支持server side rendering。当使用npm run build:ssr
构建服务器并随后使用npm run serve:ssr
运行服务器时,在节点服务器上出现以下错误:
ERROR { Error: Uncaught (in promise): Error
at resolvePromise (/project/services/frontend/dist/server.js:1003:31)
at /project/services/frontend/dist/server.js:913:17
at rejected (/project/services/frontend/dist/server/main.js:136313:93)
at ZoneDelegate.invoke (/project/services/frontend/dist/server.js:542:26)
at Object.onInvoke (/project/services/frontend/dist/server/main.js:118689:33)
at ZoneDelegate.invoke (/project/services/frontend/dist/server.js:541:52)
at Zone.run (/project/services/frontend/dist/server.js:301:43)
at /project/services/frontend/dist/server.js:1061:34
at ZoneDelegate.invokeTask (/project/services/frontend/dist/server.js:574:31)
at Object.onInvokeTask (/project/services/frontend/dist/server/main.js:118670:33)
答案 0 :(得分:2)
使用通用角度时,URL必须是绝对的。因此,要么将基本URL放在您的配置中,要么像documentation
所示那样从基础网络服务器中检索基本URL。答案 1 :(得分:0)
在服务器端添加“确定”或“拒绝”,因为您的承诺未由任何解决程序或拒绝处理。