解决方法:
@H_404_0@你可以使用这段代码 @H_404_0@@Injectable()
export class AppServices{
constructor(private http: Http) {
var obj;
this.getJSON().subscribe(data => obj=data, error => console.log(error));
}
public getJSON(): Observable<any> {
return this.http.get("./file.json")
.map((res:any) => res.json())
.catch((error:any) => console.log(error));
}
}
@H_404_0@这里file.json是你的本地json文件.
@H_404_0@也见到这里
@H_404_0@> How to get a json file in angular2 using the Http class
@H_404_0@也看到了路径的角度cli的变化
@H_404_0@> https://github.com/angular/angular-cli/blob/master/CHANGELOG.md#100-rc4-2017-03-20
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。