The length of the imagevalue array is 6.
$scope.imageValue=[];
The length of imageArray is 73.
$scope.imageArray=[];
I use for and if loop to check if any of the index in imagevalue
array is equal to any of the index in imageArray
.
for(var i = 0;i <= $scope.names.length;i++) {
for(var j=0;j<=$scope.imageID.length;j++){
if($scope.imageValue[i] == $scope.imageArray[j]) {
$scope.testArray.push($scope.imageID[j].bindaryData);
console.log($scope.testArray);
return true;
}
else if($scope.imageValue[i] !== $scope.imageArray[j]){
return false;
}
}
}
If so then I have to push the bindaydata
value in the empty array testArray
$scope.testArray=[];
My over all code looks like
angular.module('ob3App.lead')
.controller('LeadProductCtrl',['$scope','$http','filterFilter', function($scope,$http,filterFilter) {
$scope.namegetfunction = function() {
$scope.imageValue=[];
$http.get("http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/Product?l=saiy5k&p=saiy5k")
.success(function(response) {
console.log(response);
$scope.names = response.response.data;
console.log($scope.names.length);
$scope.names.forEach(function(ids){
console.log(ids.id);
$scope.imageValue.push(ids.image);
})
$scope.imageGetFunction();
console.log($scope.imageValue);
})
.error(function(response){
alert('error in name');
});
};
$scope.namegetfunction();
$scope.imageGetFunction = function() {
$scope.imageArray=[];
$scope.testArray=[];
$http.get("http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/ADImage?l=saiy5k&p=saiy5k")
.success(function(response) {
console.log(response);
$scope.imageID = response.response.data;
console.log($scope.imageID.length);
$scope.imageID.forEach(function(item) {
$scope.imageArray.push(item.id);
})
console.log($scope.imageArray);
for(var i = 0;i <= $scope.names.length;i++) {
for(var j=0;j<=$scope.imageID.length;j++){
if($scope.imageValue[i] == $scope.imageArray[j]) {
$scope.testArray.push($scope.imageID[j].bindaryData);
console.log($scope.testArray);
return true;
}
else if($scope.imageValue[i] !== $scope.imageArray[j]){
return false;
}
}
}
console.log($scope.testArray);
})
.error(function(response){
console.log(response);
alert('error in image');
});
};
}]);
See Question&Answers more detail:os