【问题标题】:Angular 4 - file not foundAngular 4 - 找不到文件
【发布时间】:2017-06-14 18:41:11
【问题描述】:

我正在使用 Angular 4,我正在尝试加载 .csv 数据,例如:http://blog.sodhanalibrary.com/2016/10/read-csv-data-using-angular-2.html 但我无法加载 sample.csv 文件。我试图将此文件添加到 src/app 或 src 或 root / 但我一直有同样的问题:

GET XHR http://localhost:4200/sample.csv [HTTP/1.1 404 Not Found 6 ms]
404 - Not Found

我正在使用 ng serve 在 localhost 上运行它。

【问题讨论】:

    标签: angular file csv http-status-code-404


    【解决方案1】:

    在 Angular 中,您可以从 assets 文件夹中访问静态文件

    将 sample.csv 文件复制到 app/assets 文件夹中。

    这样访问

    this.http.get("./sample.csv")
                .map((res: any) => res.json())
                .catch((error: any) => console.log(error));
    

    【讨论】:

      【解决方案2】:

      看起来您正在使用 Angular CLI。默认情况下,静态内容只会从 assets 文件夹中传送。您可以通过修改应用程序根目录中的 .angular-cli.json 配置文件来更改此设置。查找 assets 数组并在此处添加您的自定义文件或文件夹:

      "apps": [
          {
            "root": "src",
            "outDir": "dist",
            "assets": [
              "assets",
              "my-csv-data.csv"
            ],
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-16
        • 2017-12-15
        • 2023-02-03
        • 2017-09-14
        • 2018-03-30
        • 1970-01-01
        相关资源
        最近更新 更多