Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HI guys , below is my html file :
<mat-horizontal-stepper [linear]="isLinear" #stepper>
  <!--Merchant Resource-->
  <div [formGroup]="merchantResourceForm">
  <mat-step [stepControl]="merchantResource" >
    
      <ng-template matStepLabel>Merchant Resource</ng-template>

      <div class="example-container" ng-app="myApp" ng-controller="formCtrl">


        <table class="merchant-resource-table" cellspacing="0">
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput  ng-model="merchantName" placeholder="Merchant Name" formControlName="MerchantName" required>
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput ng-model="tradeName" placeholder="Trade Name" formControlName="TradeName" required>
              </mat-form-field>
            </td>
          </tr>
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput ng-model="registNumber" type="number" placeholder="Registration Number" formControlName="RegistNumber"
                  required>
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">

                <mat-select ng-model="language" placeholder="Language" formControlName="Language" required>
                  <mat-option>Clear</mat-option>
                  <mat-option value="English">English</mat-option>
                </mat-select>
                <!-- need to be dropdown from db. BWT_LANGUAGE-->
              </mat-form-field>
            </td>
          </tr>
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <mat-select ng-model="legalForm" placeholder="Legal Form" formControlName="legalForm" required>
                  <mat-option>Clear</mat-option>
                  <mat-option value="000">N/A</mat-option>
                </mat-select>

                <!-- need to be dropdown from db. BWT_LEGAL_FORM -->
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">
                <mat-select ng-model="businessClass" placeholder="Business Class" formControlName="businessClass" required>
                  <mat-option>Clear</mat-option>
                  <mat-option value="5012">5012 - Office and Comm</mat-option>
                </mat-select>

                <!-- need to be dropdown from db. BWT_ISO_BUSS_CLASS -->
              </mat-form-field>
            </td>
          </tr>
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <input  ng-model="extMerchId" matInput type="number" placeholder="External Merchant ID" formControlName="extMerchId"
                  maxLength=required>
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">
                <input ng-model="contactName" matInput placeholder="Contact Name" formControlName="contactName" required>
              </mat-form-field>
            </td>
          </tr>
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <mat-select ng-model="ecomInd" placeholder="E-Commerce Indicator" formControlName="ecomInd" required>
                  <mat-option>Clear</mat-option>
                  <mat-option value="000">000</mat-option>
                </mat-select>

                <!-- need to be dropdown from db. BWT_ECOMMERCE_INDICATOR -->
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">
                <mat-select ng-model="taxCountry" placeholder="Tax Country" formControlName="taxCountry" required>
                  <mat-option>Clear</mat-option>
                  <mat-option value="NZL">New Zealand</mat-option>
                </mat-select>

                <!-- need to be dropdown from db. BWT_COUNTRY -->
              </mat-form-field>
            </td>
          </tr>
          <tr>
            <td>
              <mat-form-field class="example-full-width">
                <mat-select ng-model="processRegion" placeholder="Processing Region" formControlName="processRegion" required>
                  <mat-option>Clear</mat-option>
                  <mat-option value="906">906</mat-option>
                </mat-select>

                <!-- need to be dropdown from db. BWT_REGION -->
              </mat-form-field>
            </td>
            <td>
              <mat-form-field class="example-full-width">
                <input matInput ng-model="vatNumber" type="number" formControlName="vatNumber" placeholder="VAT Registration Number">
                <!-- if left null inherit merchant ID. -->
              </mat-form-field>
            </td>
          </tr>

        </table>

        <button mat-button matStepperNext mat-raised-button color="primary"  [disabled]="!merchantResourceForm.valid "class="next-buttons">Next</button>
      </div>
   
  </mat-step>
</div>
</mat-horizontal-stepper>




And this is my .ts code:

import {Component, OnInit} from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl} from '@angular/forms';





@Component({
 // selector: 'merchant-resource',  
  templateUrl: './merchantResource.component.html',
  styleUrls: ['./merchantResource.component.css'],
})

export class MerchantResourceComponent{
  checked = true;
  panelOpenState = false;


  MerchantResourceForm = new FormGroup({

    merchantName : new FormControl(),
    tradeName : new FormControl(),
    registrationNumber : new FormControl(),
    language : new FormControl(),
    legalForm : new FormControl(),
    businessClass : new FormControl(),
    extMerchId : new FormControl(),
    contactName :  new FormControl(),
    ecomInd : new FormControl(),
    taxCountry : new FormControl(),
    processingRegion : new FormControl(),
    vatNumber : new FormControl()
   });
}


What I have tried:

I am getting the following error :
Error: formGroup expects a FormGroup instance. Please pass one in.

       Example:

       
    <div [formGroup]="myGroup">
      <input formControlName="firstName">
    </div>

    In your class:

    this.myGroup = new FormGroup({
       firstName: new FormControl()
    });


Can someone tell me what should I do?
Posted
Updated 20-Dec-20 22:33pm

This issue can happen when the FormGroup is not initialized. Please add checking using *ngIf="formName".
<pre lang="HTML"><pre><form [formgroup]="formName" *ngif="formName"></form>
 
Share this answer
 
v2
HTML
<div *ngif="sForm"> <form [formgroup]="sForm" (ngsubmit)="signin()"></form></div>
 
Share this answer
 
v2
Your HTML file:
<div [formGroup]="merchantResourceForm">

Your .ts file:
MerchantResourceForm = new FormGroup({

"merchantResourceForm" is not the same as "MerchantResourceForm"
 
Share this answer
 
Comments
Joe Doe234 20-Feb-19 4:45am    
omgg ! ... thanks bro :)
TheRealSteveJudge 20-Feb-19 4:50am    
You're welcome! Upper case / Lower case issues often are not easy to find, even for experienced developers.
Joe Doe234 20-Feb-19 4:58am    
yeahh thanks for your time brother :).

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