Sandy
Sandy

Reputation: 17

Switching icon in AngularJS with different functions

Bookmark button

What to put in ng-click to follow the functions in my controller

view.html:

  <a class="tab-item" ng-click="addBookmark('{{singleRecipe[0].recipe_id}}')">
    <i ng-class="{'icon ion-ios-pricetag': marked,'icon ion-ios-pricetag-outline' :!marked}" ng-click="marked=!marked"></i>Bookmark
  </a>

Every click of the icon the action should be different controller.js:

$scope.newBookmark={};
$scope.newBookmark.userID =  $scope.userdata.user_id;
$scope.addBookmark = function(recipe_id)
{
  $scope.newBookmark.recipeID = recipe_id;
  console.log($scope.newBookmark);
  if (!BookmarkList.add){
    BookmarkList.delfave($scope.newBookmark);
    console.log(BookmarkList.delfave);
  }else{
    BookmarkList.add($scope.newBookmark);
    console.log(BookmarkList.add);
  }
};

Upvotes: 0

Views: 50

Answers (1)

Carlo Cruz
Carlo Cruz

Reputation: 70

What you might want to do is have two links, one to add to bookmark and one to remove the bookmark and have them ng-if'd or ng-show'd.

Eg:

<a href="#" ng-click="addBookmark()" ng-if="!bookmarked">Add to bookmark</a>
<a href="#" ng-click="removeBookmark()" ng-if="bookmarked">Remove bookmark</a>

Upvotes: 1

Related Questions