For adding & removing bookmark, I am calling respective API, If already liked class is there then on clicking, removing liked class & then calling unbookmark API, if not liked the adding liked class & calling add bookmark API... but the if else condition only going in the first condition even when It should go in the else condition.
$scope.favouriteClick = function(data, isSet) { //API calls for updating server Bookmark Data
if (angular.isUndefined($scope.favorite)) {
$scope.favorite = [];
}
if ($rootScope.isUserLoggedIn == true) {
var requestParam = {
"uid": lclStorage.get('userData')[0].uid,
"token_key": lclStorage.get('userData')[0].token_key,
'career_id': isSet.mySql_career_id
}
if ($(".favorite").hasClass("liked")) {
if ($scope.favorite.indexOf(isSet.mySql_career_id) == -1) {
appServices.doAPIRequest(appSettings.appAPI_ci.getCareerBookmarks.careerBMData, requestParam, null, 'userData').then(function(data) {});
$scope.favorite.push(isSet.mySql_career_id);
} else {
appServices.doAPIRequest(appSettings.appAPI_ci.careerUnBookmarks.careerUnBData, requestParam, null, 'userData').then(function(data) {});
var index = $scope.favorite.indexOf(isSet.mySql_career_id);
$scope.favorite.splice(index, 1);
}
} else {
appServices.doAPIRequest(appSettings.appAPI_ci.careerUnBookmarks.careerUnBData, requestParam, null, 'userData').then(function(data) {});
var index = $scope.favorite.indexOf(isSet.mySql_career_id);
$scope.favorite.splice(index, 1);
}
} else {
$rootScope.openLogin();
$('.favorite').removeClass('liked');
}};
Aucun commentaire:
Enregistrer un commentaire