ChrisM
ChrisM

Reputation: 716

Use ng-click with data-ng-href

I'm trying to have a button that brings a user to the product details but id also like the button to increment a counter through an ng-click function

   <div class="row center-block save-button" >
      <a data-ng-href="/savings/{{saving._id}}" >
        <md-button aria-label="button" ng-click="upVoteHome(saving)" type="button" class="save-button-md">Save</md-button>
      </a>
    </div>

The ng-click here has no effect and never cllas the function.

How do I combine the two?

Thanks

Upvotes: 0

Views: 728

Answers (2)

danilonet
danilonet

Reputation: 1795

my suggestion is remove the ng-href, and handle only the click

<div class="row center-block save-button" >
    <md-button aria-label="button" ng-click="upVoteHome(saving)" type="button" class="save-button-md">Save</md-button>
</div>

in your controller code you can redirect the user to another view

$scope. upVoteHome = function ( saving ) {
  //YOUR EXISTING CODE HERE
  $location.path( '/savings/' + saving._id );
};

Upvotes: 0

YonatanHanan
YonatanHanan

Reputation: 48

do this:

<div class="row center-block save-button" >
        <md-button aria-label="button" ng-click="upVoteHome(saving, {{saving._id}})" type="button" class="save-button-md">Save</md-button>
</div>

and then in the upVoteHome function incremment the counter and then redirect to the url that is passed.

Upvotes: 1

Related Questions