is says i is undefined in line url: data.url[i]
??
$scope.data = [{
"url":"http://www.google.com"
},
{
"url":"http://www.bing.com"
},{
"url":"http://www.yahoo.com"
}];
angular.forEach($scope.data, function(data){
//var links = data.url;
console.log(data);
//I need array to be use in
chrome.tabs.create({
url: data.url[i]
});
});
You don't need i
at all. data
already refers to the individual item.
angular.forEach($scope.data, function(data){
chrome.tabs.create({
url: data.url
});
});
Although to avoid confusion, you might want to use a parameter name other than data
in the forEach
function, since your $scope variable is also named data
.
angular.forEach($scope.data, function(item){
chrome.tabs.create({
url: item.url
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.