Maureen Moore

Maureen Moore

  • NA
  • 206
  • 0

Property 'myForm' does not exist on type 'ShoppingCartComponent'

Jul 5 2020 7:01 PM
I have the following component html:
  1. <form *ngFor="let product of products" [formGroup]="myForm" name="myForm" (ngSubmit)="onSubmit([product.name], [product.price], int)">  
  2. <div id="cartItemsList">  
  3. <ul>  
  4. <li>  
  5. <div name="product_name">{{product.name }}</div>  
  6. <div><img src="../assets/images/gallery/{{product.thumbnail}}" /></div>  
  7. <div>{{product.price }}</div>  
  8. <button class="minus-btn" (click)="minus()" type="button" name="minus_btn">  
  9. <img src="../assets/images/minus.svg" alt="minus" /></button>  
  10. <input pattern="^(0|\+?[1-9]\d*)$" class="num" name="int" [value]="int" formControlName="int" ng-minlength="0" type="number">  
  11. <button class="plus-btn" (click)="plus()" type="button" name="plus_btn">  
  12. <img src="../assets/images/plus.svg" alt="plus" /></button>  
  13. <button type="submit" class="btnAddAction">Add to Cart</button>  
  14. </li>  
  15. </ul>  
  16. </div>  
  17. </form>  
And in the controller ts file, I have:
  1. ngOnInit(): void {  
  2. this.myForm = new FormGroup({  
  3. int: new FormControl()  
  4. });  
  5. }  
I get the following error:
ERROR in src/app/shopping-cart/shopping-cart.component.ts:80:9 - error TS2339: Property 'myForm' does not exist on type 'ShoppingCartComponent'.
80 this.myForm = new FormGroup({
but as you can see, myForm does exist in the component. How can I fix this error?

Answers (1)