[英]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.