简体   繁体   English

Angular Universal将与httpClient相处吗?

[英]Will Angular Universal get along with httpClient?

I am currently working on a project which is built mainly based on NgModules. 我目前正在研究一个主要基于NgModules构建的项目。 We have 5 different modules and multiple components and services in that. 我们有5个不同的模块以及其中的多个组件和服务。 When we tried to enable server-side rendering using Angular Universal, the pages are not rendered completely. 当我们尝试使用Angular Universal启用服务器端渲染时,页面无法完全渲染。 The code which is given below is the only part which is rendered. 下面给出的代码是唯一呈现的部分。 (view source) (查看源代码)

This issue is happening when we use httpClient in the code. 当我们在代码中使用httpClient时,就会发生此问题。 Without that everything works perfectly. 没有这些,一切都将完美运行。

<app-root _nghost-sc0="" ng-version="8.1.2"><router-outlet _ngcontent-sc0=""></router-outlet><app-main _nghost-sc1=""><!----></app-main></app-root> 

But if we check in browser's developer tools, we could see 但是,如果我们签入浏览器的开发人员工具,就会看到

<app-root _nghost-serverapp-c0="" ng-version="8.1.2"><router-outlet _ngcontent-serverapp-c0=""></router-outlet><app-main _nghost-serverapp-c1=""><!--bindings={
  "ng-reflect-ng-if": "[object Object]"
}--><div _ngcontent-serverapp-c1="" id="home-page"><app-banner _ngcontent-serverapp-c1="" _nghost-serverapp-c2="" ng-reflect-banners="[object Object],[object Object"><p _ngcontent-serverapp-c2="">banner works!</p></app-banner><app-counter _ngcontent-serverapp-c1="" _nghost-serverapp-c3="" ng-reflect-counters="[object Object],[object Object"><p _ngcontent-serverapp-c3="">counter works!</p></app-counter><app-categories _ngcontent-serverapp-c1="" _nghost-serverapp-c4="" ng-reflect-categories="[object Object],[object Object"><p _ngcontent-serverapp-c4="">categories works!</p></app-categories><app-experience _ngcontent-serverapp-c1="" _nghost-serverapp-c5="" ng-reflect-experiences="[object Object],[object Object"><p _ngcontent-serverapp-c5="">experience works!</p></app-experience><app-stay _ngcontent-serverapp-c1="" _nghost-serverapp-c6="" ng-reflect-stays="[object Object],[object Object"><p _ngcontent-serverapp-c6="">stay works!</p></app-stay><app-spotlight _ngcontent-serverapp-c1="" _nghost-serverapp-c7="" ng-reflect-spotlights="[object Object],[object Object"><p _ngcontent-serverapp-c7="">spotlight works!</p></app-spotlight></div></app-main></app-root>

I followed the official angular universal documentation. 我遵循了官方的角度通用文档。 What am I doing wrong here? 我在这里做错了什么?

The issue is solved. 问题已解决。 The problem was with the URL which is used to fetch the data. 问题在于用于获取数据的URL。 This documentation helped me from that. 文档对此提供了帮助。 Now the page is rendering completely. 现在页面已完全呈现。

Also please remember to add the httpClientModule in the app.module.ts file rather than adding to a NgModule. 另外,请记住在app.module.ts文件中添加httpClientModule ,而不要添加到NgModule中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM