无法读取未定义 AngularJS 的 属性 'push'
Cannot read property 'push' of undefined AngularJS
我的目标是根据从 API 获得的数据创建一个数组。但是它一直向我显示 cannot read property 'push' of undefined Javascript
.
的错误
谁能给我指明出路?
代码如下:
myService.getData().then(function (res) {
$scope.resoureceGroupsRawData = res.data;
//declare an array already...
$scope.resourceGroupItems = new Array();
}, function(error) {
throw error;
}).then(function() {
_.forEach($scope.resoureceGroupsRawData, function(text, idx) {
var item = {};
item.id = idx++;
item.label = text;
//why it says resourceGroupItems is null?
$scope.resouceGroupItems.push(item);
});
}, function(err) {
});
错别字兄弟,
你在几个地方拼错了资源。
myService.getData().then(function (res) {
$scope.resourceGroupsRawData = res.data;
//declare an array already...
$scope.resourceGroupItems = new Array();
}, function(error) {
throw error;
}).then(function() {
_.forEach($scope.resourceGroupsRawData, function(text, idx) {
var item = {};
item.id = idx++;
item.label = text;
//why it says resourceGroupItems is null?
$scope.resourceGroupItems.push(item);
});
}, function(err) {
//TODO need add error page here
});
我的目标是根据从 API 获得的数据创建一个数组。但是它一直向我显示 cannot read property 'push' of undefined Javascript
.
谁能给我指明出路?
代码如下:
myService.getData().then(function (res) {
$scope.resoureceGroupsRawData = res.data;
//declare an array already...
$scope.resourceGroupItems = new Array();
}, function(error) {
throw error;
}).then(function() {
_.forEach($scope.resoureceGroupsRawData, function(text, idx) {
var item = {};
item.id = idx++;
item.label = text;
//why it says resourceGroupItems is null?
$scope.resouceGroupItems.push(item);
});
}, function(err) {
});
错别字兄弟, 你在几个地方拼错了资源。
myService.getData().then(function (res) {
$scope.resourceGroupsRawData = res.data;
//declare an array already...
$scope.resourceGroupItems = new Array();
}, function(error) {
throw error;
}).then(function() {
_.forEach($scope.resourceGroupsRawData, function(text, idx) {
var item = {};
item.id = idx++;
item.label = text;
//why it says resourceGroupItems is null?
$scope.resourceGroupItems.push(item);
});
}, function(err) {
//TODO need add error page here
});