Advertisement
aironman

submit

Jun 28th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. https://stackoverflow.com/questions/16003188/can-i-trigger-a-form-submit-from-a-controller
  2.  
  3. <form ng-form-commit action="/" name='payForm' method="post" target="_top">
  4. <input type="hidden" name="currency_code" value="USD">
  5. <button type='button' ng-click='save(payForm)'>buy</button>
  6. </form>
  7.  
  8. .directive("ngFormCommit", [function(){
  9. return {
  10. require:"form",
  11. link: function($scope, $el, $attr, $form) {
  12. $form.commit = function() {
  13. $el[0].submit();
  14. };
  15. }
  16. };
  17. }])
  18.  
  19. .controller("AwesomeCtrl", ["$scope", function($scope){
  20. $scope.save = function($form) {
  21. if ($form.$valid) {
  22. $form.commit();
  23. }
  24. };
  25. }])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement