【问题标题】:How could I fetch assets files from a project inside my application?如何从我的应用程序内的项目中获取资产文件?
【发布时间】:2020-09-16 07:34:03
【问题描述】:

我在主项目中有一个应用程序(称为 http-app),我正在使用 HTTP 测试角度通信服务,遵循 guide

在 assets 文件夹中有一个 config.json 文件。

在 config.service.ts 我正在尝试获取 config.json 文件:

configUrl = 'assets/config.json'

constructor(private http: HttpClient) { }

getConfig(): Observable<Config> {
  return this.http.get<Config>(this.configUrl)
    .pipe(
      retry(3),
      catchError(this.handleError)
    );
}

但是找不到文件。结果:

有关文件夹结构的更多说明:

main-project
  projects
    http-app
      assets
        config.json <----
      src
        app
          config.service.ts
        ...
  src
    app
    ...

那么我怎样才能在项目资产文件夹中获取 config.json 文件呢?

【问题讨论】:

    标签: angular angular-httpclient angular-http


    【解决方案1】:

    相对于根目录的路径是"projects/http-app/assets/config.json"

    否则你可以尝试两个目录"../../assets/config.json"

    你能记录这个变量的值吗? 如果您使用节点模块,我不确定您的应用程序结构,您可以尝试导入

    import config from "projects/http-app/assets/config.json"
    

    【讨论】:

    • 没用...可能是因为它是一个 http/get 请求
    猜你喜欢
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 2012-05-03
    • 2014-03-10
    相关资源
    最近更新 更多