Can I trigger a form submit from a controller?

后端 未结 6 1496
独厮守ぢ
独厮守ぢ 2020-12-05 00:04

I\'d like to do a traditional form submit from within a controller. The scenario is that I want to hit a route on my web server and redirect to its response, which I can do

6条回答
  •  一个人的身影
    2020-12-05 00:50

    You can add submit method to a FormController. I did so:

    .directive("ngFormCommit", [function(){ return { require:"form", link: function($scope, $el, $attr, $form) { $form.commit = function() { $el[0].submit(); }; } }; }]) .controller("AwesomeCtrl", ["$scope", function($scope){ $scope.save = function($form) { if ($form.$valid) { $form.commit(); } }; }])

提交回复
热议问题