angular 6 form submit example

Example 1: angular submit form programmatically

// html
<form ngNoForm
    [formGroup]="testGroup"
    [action]='actionLink'
    method='POST'
    #testForm>
	<input name='Email' type='hidden' [value]='currentUserEmail'>
</form>
// ts
@ViewChild('testForm') testFormElement;
public currentUserEmail: string = '';
public testGroup = this.formBuilder.group({
  Email: ''
});
public testMethod(): void
{
  this.testFormElement.nativeElement.submit();
}

Example 2: angularjs form validation on submit

<div class="container" ng-app>

  <h1><span><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/15309/angular-logo.svg" alt="Angular.js Logo" /></span> Angular.js - Web Form</h1>

  <form role="form" name="form" id="contact-form" novalidate>
    <div class="form-group">
      <label for="FirstName">First name</label>
      <input type="text" class="form-control" name="FirstName" id="FirstName" placeholder="enter first name" ng-model="firstName" required>
    </div>

    <div class="form-group">
      <label for="LastName">Last Name</label>
      <input type="text" class="form-control" name="LastName" id="LastName" placeholder="enter last name" ng-model="lastName" required>
    </div>

    <div class="form-group">
      <label for="EmailAddress">Email address</label>
      <input type="email" class="form-control" id="EmailAddress" name="EmailAddress" placeholder="enter email" ng-model="emailAddress" ng-model-options="{ updateOn: 'blur' }" required>
    </div>

    <div class="checkbox">
      <label>
        <input type="checkbox" required> Check me out
      </label>
    </div>


    <button type="submit" class="btn btn-default" ng-disabled="form.$invalid">Submit</button>

  </form>

</div>