【发布时间】:2016-08-23 23:46:24
【问题描述】:
我与 Angular 1.5.x 的通话需要将 Devices 添加到 result.data
result.data.Devices
因此我的 Angular 1.x $http 调用是这样的:
var vm = this;
var dataService = $http;
dataService.get("http://localhost:42822/api/device")
.then(function (result) {
vm.devices = result.data.Devices;
我的 Angular 2 代码有点不同,我调用的是同一个 web api
如果我调用一个 .json 文件,那么它可以显示
private _productUrl = 'api/devices/devices.json';
但我不理解其中的一些代码,我看不到在哪里真正添加“设备”
private _productUrl = 'http://localhost:42822/api/device';
constructor(private _http: Http) { }
getProducts(): Observable<IDevice[]> {//Observable<IProduct[]> {
return this._http.get(this._productUrl)
.map((response: Response) => <IDevice[]>response.json())
.do(data => console.log("All: " + JSON.stringify(data)))
.catch(this.handleError);
}
这不是我要在“设备”或 html 模板中添加的地方吗?
【问题讨论】:
-
这可能是因为
IDevice定义。尝试使用any而不是IDevice。 -
这听起来不像是他的问题,因为他说他的 .json 文件正在工作
If I call up a .json file then it works to display所以我猜他的界面没问题。
标签: javascript angularjs json angular