如何在Angular 2中读取xml文件(从同一目录) [英] How do I read a xml file(from same directory) in Angular 2

查看:169
本文介绍了如何在Angular 2中读取xml文件(从同一目录)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Angular 2中的xml文件读取数据.

I am trying to read data from a xml file in Angular 2.

下面是我正在尝试的代码(如论坛上所建议的那样).

Below is the code I am trying(as suggested on forums).

 constructor(private http: Http) {

        this.http.get('config.xml')
                .subscribe(res => console.log(res));

      }

但是我的文件出现404错误.

But I am getting 404 error for the file.

有什么我想念的吗?

感谢您的帮助.

推荐答案

我之前遇到过同样的问题,我通过将文件放在资产文件夹中解决了该问题

I had the same problem while ago and i solved it by putting the file in the assets folder

constructor(private http: Http) {

    this.http.get('assets/config.xml')
            .subscribe(res => console.log(res));

}

这应该可以解决您的问题

This should solve your problem

这篇关于如何在Angular 2中读取xml文件(从同一目录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆