简体   繁体   English

在构建生产时获取数据,Angular

[英]Fetch data when building for production, Angular

I'm building an Angular application that needs to get some data from a server, the data is not changing very often so I don't want to make a request every time someone loads the application, I would rather make a call every time I build the app and have it as part of the bundle. 我正在构建一个需要从服务器获取一些数据的Angular应用程序,数据不会经常更改所以每次有人加载应用程序时我都不想发出请求,我宁愿每次都拨打一个电话构建应用程序并将其作为捆绑包的一部分。

So my question is: is there a way to fetch data from a server when building, and using it in the application? 所以我的问题是:有没有办法在构建时从服务器获取数据,并在应用程序中使用它? (and for serving in dev mode it should maybe fetch on each build) (并且对于在开发模式下服务,它应该可以在每个构建上获取)

I think you are looking for Angular Universal prerendering. 我认为你正在寻找Angular Universal预渲染。 It's quite complex to describe in one short answer, but you can start exploring for instance from this tutorial: 💥 Angular Universal: Pre-Rendering with renderModuleFactory 在一个简短的答案中描述它是相当复杂的,但是您可以从本教程开始探索: 💥AngularUniversal:使用renderModuleFactory进行预渲染

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

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