One of the features in my app involves retrieving data from an API and storing it in $scope.newz
.
The previous user activity is loaded from LocalStorage as bookmarkData
.
I am facing a challenge with comparing the contentId values in arrays $scope.newz and $scope.bookmarkData.
My goal is to set bookmarkstate : true
only for items that match between these two arrays.
Upon finding matches, I want to include those records in $scope.AllnewsList
.
Take a look at the code snippet below:
if(data.Status.ResponseCode == 200)
{
$("#fetchnews").hide();
// $("#nodata").show();
$("#sError").hide();
//$scope.AllnewsList = data.contents;
$scope.newz = data.contents;
$scope.bookmarkData = JSON.parse(window.localStorage.getItem('bookmark'));
for (var i=0; i < $scope.newz.length; i++)
{
for (var j=0; j < $scope.bookmarkData.data.length; j++)
{
if ($scope.newz[i].ContentId == $scope.bookmarkData.data[j].ContentId)
{
// console.log($scope.newz[i].ContentId);
$scope.bookmarkstate == true;
}
else
{
$scope.bookmarkstate == false;
}
}
}
$scope.AllnewsList = $scope.newz;
}