Reputation: 147
Using AngularJs, I have a web page where I have three buttons to call a method. Each button currently has its own ng-click attribute, and calls the same method but passes a different parameter:
<button type="submit" ng-click="main.save(131)" title="Set Ready to Ship" class="btn btn-primary btn-header" ng-disabled="!main.allowedToShip || main.isLoading" ng-show="main.allowedToShip">
<span class="icon-truck icon"></span>
</button>
<button type="submit" ng-click="main.save(132)" title="Set in Use" class="btn btn-primary btn-header" ng-disabled="!main.allowedInUse || main.isLoading" ng-show="main.allowedInUse">
<span class="icon-meter icon"></span>
</button>
<button type="submit" ng-click="main.save(130)" title="Save" class="btn btn-primary btn-header" ng-disabled="!main.allowedModify || main.isLoading">
<span class="icon-floppy-disk icon"></span>
</button>
I have made a form on that page, and I want to have the buttons to use the ng-submit of the form instead of their current ng-click method. However, I don't know how I can pass the correct parameters to the ng-submit. I feel like I'm missing an obvious solution. Can someone help me? Thank you.
Upvotes: 2
Views: 554
Reputation: 15031
In your 3 buttons, instead of passing a parameter, set a $scope.someVariable
with the value (which will be different for the 3 button clicks)...
Afterwards, in the submit function running as a result of <input type="submit" style="display:none">
click... you can process this $scope.someVariable
Upvotes: 2