Wie kann man die AngularJS-Validierung manuell über eine Schaltfläche außerhalb der Formular-Tags auslösen?

Gegeben diesen Code:

<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"/>
    </form>

    <hr/>

    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>


</div>


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

function MyCtrl($scope) {

    $scope.onSubmitted = function() {
        alert('submitted!');
    };
}

Ich möchte, dass die letzte Schaltfläche die Validierung auf dem ersten Formular auslöst (und dann übermittelt, wenn die Dinge gültig sind). Ab sofort kann nur die Schaltfläche im Formular die Validierung und Übermittlung des Formulars auslösen. Gibt es eine Möglichkeit für eine Schaltfläche außerhalb des Formulars, das auszuführen?

Live-Test:http://jsfiddle.net/dzjV4/1/

Antworten auf die Frage(6)

Ihre Antwort auf die Frage