简体   繁体   English

Angular 5-从资产文件夹下的JSON文件中获取数据

[英]Angular 5 - Fetching data from the JSON file under the asset folder

Our application is dynamically generating the Form from a .json file which is placed under the assets folder. 我们的应用程序是从.assets文件下的.json文件动态生成表单的。 The problem we are facing is before the .json file is loaded, our component is rendered and as a result we are seeing null values in the form. 我们面临的问题是在加载.json文件之前,呈现了我们的组件,因此,我们在表单中看到空值。

We tried to load the .json using service (HttpClient) and call that from the main component (AppComponent) but still the loading is taking time and our actual component is been rendered and showing null values as .json file is loaded after the actual component is rendered 我们尝试使用服务(HttpClient)加载.json并从主组件(AppComponent)调用它,但是加载仍然需要时间,并且我们的实际组件已呈现,并在实际组件加载后显示.json文件为空值被渲染

Try like this: 尝试这样:

let filePath = "/assets/file.json";

this.http.get(filePath).subscribe((res: any) => {
    console.log(res)
});

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

相关问题 Angular-FusionCharts:如何从外部.json文件获取数据? - Angular-FusionCharts : How to fetching data from external .json file? 使用 angular 从服务器端 php 文件中获取 json 数据? - Fetching json data from server-side php file with angular? 有没有办法在 angular 项目的资产文件夹中编辑 JSON 文件? - Is there a way to edit a JSON file within the asset folder of an angular project? 在Angular2中从JSON获取数据不起作用 - Fetching data from JSON in Angular2 not working 从 angular 中的 json 中的数组获取数据 - fetching data from array inside json in angular 从 angular 应用程序中的资产文件夹文件加载动态 html 内容 - Load dynamic html content from asset folder file in angular application 除了Http/fetch之外,还有什么方法可以读取angular资产文件夹下的svg文件的内容? - Is there any way to read the contents of svg file placed under asset folder in angular other than Http/fetch .? 无法从 Angular 的本地文件夹中的 JSON 文件中读取数据 7 - Can't read data from JSON file in local folder in Angular 7 从资产导入 Json 文件 - Angular Production Build 问题 - Import Json file from asset - Angular Production Build Issue 通过服务从json文件中获取数据在Angular4中给出了“意外的输入结束” - Fetching data from json file via service is giving “unexpected end of input” in Angular4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM