简体   繁体   中英

HTML javascript how to chnage target value for href

I am trying to change the target of

 <a ng-hide="cart.getTotalCount() < 1" class="btn btn-primary btn-block" href="./Checkout"> 

My intention is to pass one parameter to Checkout method depending on circumstance. I want to achieve this in HTML/Javascript

To answer your question you can do :

<a ng-hide="cart.getTotalCount() < 1" class="btn btn-primary btn-block" ng-href="{{computeCheckoutUrl()}}">

And you can have in your controller something like

$scope.computeCheckoutUrl = function() {
   if (test)
     return './Checkout?var=2';
   return './Checkout';
};

But I recommend you to take a look at built-in tools like ngRoute to do things like that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM