There is a script. Need a little to redo it.
The essence of the script is to check if there is a service in the favorites array on which the user presses. Add / remove from favorites.
$scope.manageFavorService = function (serviceId) { var data = {};//sending an empty array to get response getService = serviceId; PortalApi.getFavorServices(data)//get an array with all favorites services .then(function(data) { function isFavorite(id)//looking if there already serviceId exist { return data.filter(function(data) { return data.service_id== id}); } var isFavorite = isFavorite(getService), data = {serviceId:serviceId}; if (isFavorite.length == 0) {//add favorite if in answer we got empty array PortalApi.addFavorServices(data); } else {//del favorite if in answer we got array with our service PortalApi.delFavorServices(data); } }); }; PortalApi.getFavorServices
getFavorServices: function(data) { var defer = $q.defer(); watchResponse(function() { return services.one('receivers').one('getFavorServices').post('', { data: data }); }, function(response) { return defer.resolve(response); }, function(reason) { return defer.reject(reason); }); return defer.promise; }, I can not understand how to add it so that it would be possible to call the isFavorite check in the html code, for example, to change the button class. project on angularjs
I want to check there
ng-class="{'glyphicon-heart' : isFavorite , 'glyphicon-heart-empty' : !isFavorite }" overall button
<button ng-if="auth.user" ng-click="manageFavorService(service.id)" class="fa favorite-service" ng-class="{'fa-star' : isFavorite , 'fa-star-o' : !isFavorite }" uib-tooltip="{{!isFavorite ? 'SERVICES.FAVORITES.ADDTO' : 'SERVICES.FAVORITES.DELFROM' | translate}}" tooltip-placement="left"></button>
PortalApi.getFavorServices- Grundyvar isFavorite = isFavoritebetter not to do - Grundy