Kob*_*uek 1 angular-http angular
我正在尝试使用Angular2中的htttp.get读取JSON文件。
当我在项目上使用本地存储的文件时,它工作正常。
但是-当我使用具有完全相同文件的远程服务器时,出现以下错误:
404-找不到集合“未定义”
浏览到http://example.com/my.json,我可以在任何浏览器上看到该文件。
这是我获取文件的打字稿代码:
private url = '../my.json'; <--- This works
private url = 'http://example.com/my.json'; <--- This throws the error
return this.http.get(this.url)
.map(this.extractData)
.catch(this.handleError);
Run Code Online (Sandbox Code Playgroud)
提前致谢。
Not found collection错误提示您以前使用angular-in-memory-web-api过。您需要从项目中删除与之相关的所有内容,这相当于从imports您NgModule的以下项目中删除:
InMemoryWebApiModule.forRoot(InMemoryDataService)
Run Code Online (Sandbox Code Playgroud)
这样您就可以使用外部api和db。
否则,您的代码不应更改,但是如果需要,遵循本教程将对您有所帮助。
| 归档时间: |
|
| 查看次数: |
2418 次 |
| 最近记录: |