【发布时间】:2017-04-11 01:25:13
【问题描述】:
我正在尝试使用 Ionic2,并且我提供了一项服务来获取本地存储的 Json。
import {Injectable} from 'angular2/core';
import {Http, Response} from 'angular2/http';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
@Injectable()
export class Page1Service {
public constructor(private _http: Http) {}
public GetItems() {
return this._http.get('/app/Ressources/Items.json').map((response: Response) => response.json().data);
}
public PrintJson():boolean {
var myresult;
this.GetItems().subscribe((result) => {
myresult = result;
console.log(result);
});
}
我还有一个 PrintJson() 方法,它只是打印 json 用于测试目的。我得到了错误:
GET http://localhost:8100/app/Ressources/slides.json 404 (Not Found)
我不明白为什么。而且我找不到简单且最新的教程。还是应该使用 fetch()?
【问题讨论】:
-
您能否访问带有 200 状态码的 Ionic2 应用程序之外的 URL?
-
在 angular2 应用程序中...我复制粘贴代码并更改我需要的内容。 (我发现了你的博客!感谢你的文章)。路径是对的。
-
你也试过
'app/Ressources/Items.json'吗?