Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in component
--------------------

ngOnInit() {

    this.registerForm = this.formBuilder.group({
      firstName: [],
      lastName: [],
 
    });
    
  }



in html
--------------
<form [formGroup]="registerForm" (ngSubmit)="onSubmit()">

                         <div class="row">
                             <div class="col-md-4">
                               <mat-form-field class="example-full-width">
                                 <input formControlName="firstName"  matInput  placeholder="Fist Name" type="text">
                               </mat-form-field>
                             </div>

                             <div class="col-md-4">
                               <mat-form-field class="example-full-width">
                                 <input formControlName="lastName"  matInput placeholder="Last Name" type="text">
                               </mat-form-field>
                             </div>
                         </div>
                         <button mat-raised-button type="submit"  class="btn btn-danger pull-right">Register</button>
                         <div class="clearfix"></div>
                     </form>


in appmodule
------------------

imports: [
    BrowserModule,
    CommonModule,
    BrowserAnimationsModule,
    HttpModule,
    ComponentsModule,
    RouterModule,
    AppRoutingModule,
    MatButtonModule,
    MatFormFieldModule,
    MatInputModule,
    MatRippleModule,
    HttpClientModule,
    ReactiveFormsModule,


What I have tried:

i have tried angular 6 form group example
Posted
Updated 24-Dec-18 19:24pm

1 solution

Import below modules into module in which your current component belongs to.
FormsModule,
  ReactiveFormsModule
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900