0

I am making a form in angular application.. I have imported FormsModule from '@angular/forms' in app.module.ts but then still I am getting No provider for ControlContainer

Error log:

Uncaught Error: Template parse errors:
No provider for ControlContainer ("
                <span>Product Catalog</span>
            </h4>
        [ERROR ->]<form [formGroup]="productSearchForm" (ngSubmit)="onSubmit()" class="d-flex md-form justify-content-c"): ng:///ViewsModule/ProductCatalogComponent.html@8:8
No provider for NgControl ("orm" (ngSubmit)="onSubmit()" class="d-flex md-form justify-content-center form-inline">
            [ERROR ->]<select class="custom-select mb-2 mr-sm-2 mb-sm-0" formControlName="f_categoryId">
            <optio"): ng:///ViewsModule/ProductCatalogComponent.html@9:12
No provider for NgControl ("
            </select>

            [ERROR ->]<input type="search" formControlName="f_productDescription" placeholder="Seach the products" aria-lab"): ng:///ViewsModule/ProductCatalogComponent.html@16:12
    at syntaxError (compiler.js:215)
    at TemplateParser.push../node_modules/@angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14702)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:22709)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:22696)
    at compiler.js:22639
    at Set.forEach (<anonymous>)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22639)
    at compiler.js:22549
    at Object.then (compiler.js:206)
    at JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)

My code is as below,

product-catalog.component.html

<div class="card mb-4 wow fadeIn">
    <div class="card-body d-sm-flex justify-content-between">
            <h4 class="mb-sm-0 pt-3">
                <span>Product Catalog</span>
            </h4>
        <form [formGroup]="productSearchForm" (ngSubmit)="onSubmit()" class="d-flex md-form justify-content-center form-inline">
            <select class="custom-select mb-2 mr-sm-2 mb-sm-0" formControlName="f_categoryId">
            <option selected>Choose Category</option>
            <option value="1">One</option>
            <option value="2">Two</option>
            <option value="3">Three</option>
            </select>

            <input type="search" formControlName="f_productDescription" placeholder="Seach the products" aria-label="Search" class="form-control">      
            <button type="submit" class="btn btn-primary"> <i class="fa fa-search"></i></button>
        </form>
    </div>
</div>

product-catalog.component.ts

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import { InventoryService } from '../../_services/inventory.service';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ProductView } from '../../_models/product-view';
import { Category } from '../../_models/category';
import { OrderService } from '../../_services/order.service';

@Component({
  selector: 'app-product-catalog',
  templateUrl: 'product-catalog.component.html',
  styleUrls: ['product-catalog.component.scss'],
})
export class ProductCatalogComponent implements OnInit {

  public selectedId;
  public products: ProductView[];
  public categories: Category[];
  productSearchForm: FormGroup;

  constructor( private router: Router, private route: ActivatedRoute, 
     private inventoryService: InventoryService, private formBuilder: FormBuilder
    , private orderService: OrderService ) { }

  ngOnInit() {
    this.productSearchForm = this.formBuilder.group({
      f_productDescription: ['', Validators.required],
      f_categoryId: []
    });

    this.route.paramMap.subscribe(
      (params : ParamMap) => {
        this.selectedId = params.get('id');
      }
    );

    this.inventoryService.getProductCategories()
               .subscribe(data => this.categories = data) 
  }


  onSubmit(){
    //stop here if form is invalid
    if (this.productSearchForm.invalid) {
        return;
    }
    console.log('--------product-catalog.component.ts------------onSubmit()---------'+JSON.stringify(this.productSearchForm.value));
     this.inventoryService.getProducts(this.productSearchForm.value)
                .subscribe(data => this.products = data); 
  }

  onSelect(product){
    this.router.navigate(['/products',product.id]);
  }

  addToCart(product){
    console.log('--------product-catalog.component.ts------------addToCart()---------productId:'+product.productId);
     this.orderService.addToCart(product.productId,1)
    .subscribe(data => console.log("data:"+JSON.stringify(data)));

  }

  isSelected(product) { return product.id == this.selectedId; }
}

view.module.ts

import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { FooterComponent } from '../main-layout/footer/footer.component';
import { Dashboard1Component } from './dashboards/dashboard1/dashboard1.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { ProductCatalogComponent } from './product-catalog/product-catalog.component';

@NgModule({
  imports: [
    CommonModule,
    RouterModule,
    FormsModule,
    BrowserModule,
    BrowserAnimationsModule,
    MDBBootstrapModule.forRoot(),
  ],
  declarations: [
    FooterComponent,
    Dashboard1Component,
    ProductCatalogComponent
  ],
  exports: [
    FooterComponent,    
    Dashboard1Component,
    ProductCatalogComponent
  ],
  schemas: [NO_ERRORS_SCHEMA]
})
export class ViewsModule { }

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule, NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { AppRoutes } from './app.routes.service';
import { MDBBootstrapModule } from 'angular-bootstrap-md';

import { ViewsModule } from './views/views.module';
import { ErrorModule } from './views/errors/error.module';
import { HttpClientModule } from '@angular/common/http';

// main layout
import { NavigationModule } from './main-layout/navigation/navigation.module';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    NavigationModule,
    AppRoutes,
    RouterModule,
    ViewsModule,
    ErrorModule,
    FormsModule, 
    ReactiveFormsModule,
    MDBBootstrapModule.forRoot(),
    HttpClientModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
  schemas: [ NO_ERRORS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppModule { }

Please help me.. Thanks in advance..

2 Answers 2

1

import { FormsModule, ReactiveFormsModule } from '@angular/forms';

within view.module.ts

Sign up to request clarification or add additional context in comments.

Comments

0

It's not FormsModule, it's ReactiveFormsModule.

1 Comment

Ok.. got it.. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.