How to trigger form submit programmatically in AngularJS?

后端 未结 3 542
遇见更好的自我
遇见更好的自我 2021-01-06 00:48

From Angular\'s documentation it follows that ngSubmit is a preferred way of submitting a form. All pending operations are immediately finished and $submitted f

3条回答
  •  既然无缘
    2021-01-06 01:29

    app.directive("form", function(){
         return {
            require: 'form',
            restrict: 'E',
            link: function(scope, elem, attrs, form) {
                form.doSubmit = function() {
                    form.$setSubmitted();
                    return scope.$eval(attrs.ngSubmit);
                };
            }
        };
    });
    

    Html:

    Then call in controller

    $scope.myForm.doSubmit();
    

提交回复
热议问题