0
我想顯示數組中的數據,但我不知道如何去做。使用角度顯示數組中的數據
這裏是我來回文件service.js一個片段:
this.getdata = function() {
var myData = $resource('url', {method: 'get', isArray: true});
myData.prototype.destroy= function(callback) {
return reffs.remove({id: this.id},callback);
};
return myData;
};
從控制器:
$scope.data = myservice.getdata().query;
alert($scope.data.length) // getting 4
alert($scope.data[1].id) // getting undefined
alert($scope.data[1]) // getting undefined
我也試過:
alert(JSON.parse($scope.data[1]).id)
alert(JSON.stringify($scope.data[1]).id)
alert(JSON.stringify($scope.data))
我的alert(data.length)
有4但沒有其他工作:(如何將它們寫入alert
或html?
打開Firebug或DevTool NETWORK控制檯,查看您的服務返回的數據。 –
如果你寫'console.log($ scope.data);'?在Firebug中,您可以查看數組元素。 –