如何获取内联或嵌入的 JSON 文件数据

How to get inline or embedded JSON file data

你能告诉我如何获取内联或嵌入的 JSON 文件吗?

错误:

polyfills.js:3 GET http://localhost:8100/data/questions.json 404 (Not Found)

文件夹路径:

调查-data.ts

    @Injectable()
    export class SurveyData {

      constructor(public http: Http) {

      }

     getJson(): Observable<any> {
        return this.http.get("data/questions.json") //not working here
          .map(this.extractData)
          .catch(this.handleError);

      }
}

questions.json

{
    "28903218": {
        "type": "group", 
        "prompt": "Cool, thanks! Now tell us about your child's day:", 
        "description": ""
    }, 
}

data文件夹放入www文件夹。它起作用的原因是因为 www 文件夹就像 "server" 的根目录。这是在运行时提供静态内容的地方。除了 src 文件夹中的其他内容之外,只有 assets 文件夹被添加到 www 文件夹,.ts 文件被编译为单个入口点文件并添加到 www/build。在你的情况下 data 不会被转移。您可以在构建时检查内容。