莫比它只是监督,但我不能控制台登录值我怎样才能控制台登录此对象
所以,当我登录这个
console.log($scope.data)
比我在网页上的控制台找回
$$state: Object
status: 1
value: Array[11]
0: Object
1: Object
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object
10: Object
我只想说,
console.log($scope.data.value[0])
给我的只是价值中的第一个对象。 但我只使用任何我尝试使用的未定义。 我错过了什么,我不能单独得到我的价值的对象。 Maby这是一个角度的事情,因为$$,但即时通讯有点现在。
张贴我的代码Here is a screenshot of what I get when I console log the data
更新如何得到我的数据:
厂
(function() {
'use strict';
angular
.module('testApp')
.factory('storage', storage);
storage.$inject = ['$http'];
function storage($http) {
return {
getData: getData
};
function getData() {
return $http.get('http://localhost:4040/')
.then(complete)
.catch(failed);
function complete(response) {
var merge = data.teams.map (function (data) {
data.members = response.data.filter (function (person) {
return person.room == data.rooms
});
return data;
});
return merge;
}
function failed(error) {
console.log('getting the data has failed' + error.data);
}
}
}
})();
服务
(function() {
'use strict';
angular
.module('testApp')
.service('testStorage', testStorage);
testStorage.$inject = ['storage'];
function testStorage(storage) {
//Create empty variables
//Data in variables
var allData = storage.getData();
//Return functions
var service = {
getAll: getAll
};
return service;
///////////////////////////
// Create functions here //
///////////////////////////
function getAll() {
return allData;
}
}
})();
,并最终我的控制器
(function() {
'use strict';
angular
.module('testApp')
.controller('tryOutController', tryOutController);
tryOutController.$inject = ['$scope', 'testStorage'];
function tryOutController($scope, testStorage) {
$scope.data = {};
$scope.data = testStorage.getAll();
console.log($scope.data);
}
})();
你可以像'$ scope.data。$$ state.value [0]'那样访问它,但这不是你应该做的。发布代码以获得更好的解决方案你如何填充这个'$ scope.data'? – dfsq
叶我也会说,但我回来'TypeError:无法读取属性未定义'0'。但不知道如何重新创建这个问题,因为它对我来说是非常新的,也从来没有遇到过麻烦。 – Dennis
不要重新创建问题,发布代码,如何填充$ scope.data? – dfsq