snapjay / ngCart

Really simple shopping cart for AngularJS
http://ngcart.snapjay.com
380 stars 236 forks source link

How to dynamically change setShipping #19

Closed al5dy closed 9 years ago

al5dy commented 9 years ago

Hello! I need at the touch of a button to change the value of html that takes setSnipping. Tell me how it can be implemented in a standard piece of code? var myApp = angular.module ('myApp', ['ngCart']);

myApp.controller ('myCtrl', ['$ scope', '$ http', 'ngCart', function ($ scope, $ http, ngCart) {

     ngCart.setTaxRate (0);

     ngCart.setShipping (200.00);

}]);

snapjay commented 9 years ago

Try adding a function onto the scope of your controller as below and then call it from the button with an ng-click

<button ng-click="changeShipping(200)">Set Shipping</button>
var myApp = angular.module ('myApp', ['ngCart']);
myApp.controller ('myCtrl', ['$scope', '$http', 'ngCart', function ($scope, $http, ngCart) {

$scope.changeShipping = function(amount) {
    ngCart.setShipping (amount);
}

}]);

Please note this is not a issue with the plugin and not related to ngCart; Please refer to AngularJS documentation for further help.