You must put ng-model in each field to include the form in each field. If you do not add ng-model and name with a value, your field will never be considered part of your form. And change one thing, create one parent variable, such as form , and add all scope variables to it. as in the controller do $scope.form = {}; and then in the UI add all the ng-model to it like form.email , form.password and form.confirmation .
To verify the form more correctly, remove the action and method attribute from the form and use the ng-submit directive, which will call one of the controller methods. and Do call post from this controller method by checking the form $valid or not.
Markup
<form name="signUpForm" ng-submit="submit(signUpForm, form)" novalidate> <fieldset> <div class="field input-field"> Email <br /> <input type="email" name="email" ng-model="form.email" required /> </div> <div class="field input-field"> Password <br /> <input type="password" ng-model="form.password" name="password" required /> </div> <div class="field input-field"> Confirm Password <br /> <input type="password" ng-model="form.confirmation" name="confirmation" required /> </div> !! -- Form valid? {{signUpForm.$valid}} -- !! <div class="actions"> <input type="submit" value="Sign Up" /> </div> </fieldset> </form>
controller
$scope.submit = function(form, formData) { if (form.$valid) { //submit form if it is valid $http.post('/url', { data: formData }) .success(function() { //code here }) .error(function() { }) } else { alert("Please fill all required fields") } }
Hope this cleared your little concept of form, thanks.
Pankaj parkar
source share