javascript – 如何从表单标签之外的按钮手动触发AngularJS验证?


<div ng-controller="MyCtrl">
    <form ng-submit="onSubmitted()">

    Header inputs:
        <input type="name" ng-model="sample" required/>
        <input type="name" ng-model="sampleX" required/>

        <input type="submit" value="This submit triggers validation. But I wanted to put this button at the end of the page"/>


    Some other form here. Think line items

    <hr />
    <a class="btn" ng-click="/* what could should be put here, so this can trigger the firt form's validation, then submit? */">Wanted this submit button to trigger the validation+submit on the form in which this button doesn't belong</a>


var app = angular.module('myApp', []);

function MyCtrl($scope) {

    $scope.onSubmitted = function() {



您可以创建指令,然后您可以附加到< a class =“btn”....检查此jsfiddle

请注意,我添加到< input type ='submit'id ='clickMe'...并将其链接到底部的< a class ='btn'linked =“clickMe”...

转载注明原文:javascript – 如何从表单标签之外的按钮手动触发AngularJS验证? - 代码日志