-1

When a button is clicked I wanted to pass the value of the input field which has the formControlName email to the function , can someone give me an idea or help ? thank.

#html code

<div>
                    <div fxLayout="column">
                        <mat-form-field class="full-width" appearance="fill" style="margin-top: 20px;">
                            <mat-label>Username</mat-label>
                            <input matInput placeholder="" autocomplete="email" formControlName="email">
                            <mat-error *ngIf="modelForm.get('email').hasError('required')">
                                Username is required.
                            </mat-error>
                        </mat-form-field>
                    </div>
                    <div style="text-align: right;">
                        <button (click)="getStarted()" mat-flat-button color="primary"
                            type="submit" class="v-btn-sml" id="get-started-button">
                            Submit
                        </button>
                    </div>

#.ts

  getStarted() {
    // I want to pass the input value from the username field here when button is clicked
  }

  private Form(): FormGroup {
    return this.formBuilder.group({
      id: [this.model.id || 0],
      email: new FormControl(this.model.email, [Validators.required]),
    });
  }
Art McAhon
  • 21
  • 2
  • 8

2 Answers2

3

Assuming you have defined modelForm as a property on your component,

getStarted(){
    const value = this.modelForm.value['email'];
}
2

u can achieve it this way:

getStarted() {
   const inputValue = this.modelForm.get('email').value
  }

 
gil
  • 2,388
  • 1
  • 21
  • 29