formGroup]still not working and I have FormsModule and ReactiveFormsModule

✘ [ERROR] NG8002: Can’t bind to ‘formGroup’ since it isn’t a known property of ‘form’. [plugin angular-compiler]

app.module.ts

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { provideHttpClient, withFetch, withInterceptorsFromDi } from "@angular/common/http";
import { ApiServiceService } from './api-service.service';
import { RouterModule } from "@angular/router";
import { AppComponent } from "./app.component";
@NgModule({
declarations: [],
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpClientModule,
RouterModule,
],
providers: [
provideHttpClient(withFetch(), withInterceptorsFromDi()),
ApiServiceService
],
bootstrap: [AppComponent, ReactiveFormsModule]
})
export class AppModule { }
</code>
<code>import { NgModule } from "@angular/core"; import { BrowserModule } from "@angular/platform-browser"; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http"; import { provideHttpClient, withFetch, withInterceptorsFromDi } from "@angular/common/http"; import { ApiServiceService } from './api-service.service'; import { RouterModule } from "@angular/router"; import { AppComponent } from "./app.component"; @NgModule({ declarations: [], imports: [ BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, RouterModule, ], providers: [ provideHttpClient(withFetch(), withInterceptorsFromDi()), ApiServiceService ], bootstrap: [AppComponent, ReactiveFormsModule] }) export class AppModule { } </code>
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { provideHttpClient, withFetch, withInterceptorsFromDi } from "@angular/common/http";
import { ApiServiceService } from './api-service.service';
import { RouterModule } from "@angular/router";
import { AppComponent } from "./app.component";

@NgModule({
  declarations: [],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpClientModule,
    RouterModule,
  ],
  providers: [
    provideHttpClient(withFetch(), withInterceptorsFromDi()),
    ApiServiceService
  ],
  bootstrap: [AppComponent, ReactiveFormsModule]
})
export class AppModule { }

form html:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><div class="mt-4 ml-4">
<form [formGroup]="animalForm" id="animalForm">
<div class="form-row">
<div class="col">
<label class="form-id-label" for="id">ID:</label>
<input type="text" class="form-control" id="id" formControlName="id" autocomplete="off" />
</div>
<div class="col">
<label class="form-name-label" for="name">Name:</label>
<input type="text" class="form-control" id="name" formControlName="name" autocomplete="off" />
</div>
<div class="col">
<label class="form-description-label" for="description">Derscription:</label>
<input type="text" class="form-control" id="description" formControlName="description" autocomplete="off" />
</div>
<!-- Hidden input for created_At -->
<input type="hidden" id="created_At" name="created_At" formControlName="created_At" />
<!-- Hidden input for updated_At -->
<input type="hidden" id="updated_At" name="updated_At" formControlName="updated_At" />
<button (click)="animalSubmit()" type="submit" class="btn btn-primary mt-4 ml-2 mr-4">
Create New Animal
</button>
<button (click)="updateAnimal()" type="submit" class="btn btn-success mt-4 ml-2 mr-4" *ngIf="getparamid">
Update Animal
</button>
</div>
</form>
</div>
</code>
<code><div class="mt-4 ml-4"> <form [formGroup]="animalForm" id="animalForm"> <div class="form-row"> <div class="col"> <label class="form-id-label" for="id">ID:</label> <input type="text" class="form-control" id="id" formControlName="id" autocomplete="off" /> </div> <div class="col"> <label class="form-name-label" for="name">Name:</label> <input type="text" class="form-control" id="name" formControlName="name" autocomplete="off" /> </div> <div class="col"> <label class="form-description-label" for="description">Derscription:</label> <input type="text" class="form-control" id="description" formControlName="description" autocomplete="off" /> </div> <!-- Hidden input for created_At --> <input type="hidden" id="created_At" name="created_At" formControlName="created_At" /> <!-- Hidden input for updated_At --> <input type="hidden" id="updated_At" name="updated_At" formControlName="updated_At" /> <button (click)="animalSubmit()" type="submit" class="btn btn-primary mt-4 ml-2 mr-4"> Create New Animal </button> <button (click)="updateAnimal()" type="submit" class="btn btn-success mt-4 ml-2 mr-4" *ngIf="getparamid"> Update Animal </button> </div> </form> </div> </code>
<div class="mt-4 ml-4">
  <form [formGroup]="animalForm" id="animalForm">
    <div class="form-row">
      <div class="col">
        <label class="form-id-label" for="id">ID:</label>
        <input type="text" class="form-control" id="id" formControlName="id" autocomplete="off" />
      </div>
      <div class="col">
        <label class="form-name-label" for="name">Name:</label>
        <input type="text" class="form-control" id="name" formControlName="name" autocomplete="off" />
      </div>
      <div class="col">
        <label class="form-description-label" for="description">Derscription:</label>
        <input type="text" class="form-control" id="description" formControlName="description" autocomplete="off" />
      </div>

      <!-- Hidden input for created_At -->
      <input type="hidden" id="created_At" name="created_At" formControlName="created_At" />

      <!-- Hidden input for updated_At -->
      <input type="hidden" id="updated_At" name="updated_At" formControlName="updated_At" />

      <button (click)="animalSubmit()" type="submit" class="btn btn-primary mt-4 ml-2 mr-4">
        Create New Animal
      </button>

      <button (click)="updateAnimal()" type="submit" class="btn btn-success mt-4 ml-2 mr-4" *ngIf="getparamid">
        Update Animal
      </button>
    </div>
  </form>
</div>

component:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>animalForm = new FormGroup({
id: new FormControl('', Validators.required),
name: new FormControl('', Validators.required),
description: new FormControl('', Validators.required),
created_At: new FormControl(new Date().toISOString()),
updated_At: new FormControl(new Date().toISOString()),
});
animalSubmit() {
console.log('COME ON HELL WHERE ARE YOU');
console.log(this.animalForm.value);
if (this.animalForm.value) {
console.log(this.animalForm.value);
const res = this.api.createAnimal(this.animalForm.value);
console.log(res, 'Data Added Successfully');
// this.animalForm.reset();
// this.successMsg = res.message;
// this.getAlldata();
} else {
this.errMsg = 'All Fields Are Required';
}
}
updateAnimal() {
console.log('update animal function in component??');
console.log(this.animalForm.value);
if (this.animalForm.value) {
const res = this.api.updateData(this.animalForm.value, this.getparamid);
console.log(res, 'Data Updated Successfully');
// this.successMsg = res.message;
// this.getAlldata();
} else {
this.errMsg = 'All Fields Are Required';
}
}
}
</code>
<code>animalForm = new FormGroup({ id: new FormControl('', Validators.required), name: new FormControl('', Validators.required), description: new FormControl('', Validators.required), created_At: new FormControl(new Date().toISOString()), updated_At: new FormControl(new Date().toISOString()), }); animalSubmit() { console.log('COME ON HELL WHERE ARE YOU'); console.log(this.animalForm.value); if (this.animalForm.value) { console.log(this.animalForm.value); const res = this.api.createAnimal(this.animalForm.value); console.log(res, 'Data Added Successfully'); // this.animalForm.reset(); // this.successMsg = res.message; // this.getAlldata(); } else { this.errMsg = 'All Fields Are Required'; } } updateAnimal() { console.log('update animal function in component??'); console.log(this.animalForm.value); if (this.animalForm.value) { const res = this.api.updateData(this.animalForm.value, this.getparamid); console.log(res, 'Data Updated Successfully'); // this.successMsg = res.message; // this.getAlldata(); } else { this.errMsg = 'All Fields Are Required'; } } } </code>
animalForm = new FormGroup({
    id: new FormControl('', Validators.required),
    name: new FormControl('', Validators.required),
    description: new FormControl('', Validators.required),
    created_At: new FormControl(new Date().toISOString()),
    updated_At: new FormControl(new Date().toISOString()),
  });

  animalSubmit() {
    console.log('COME ON HELL WHERE ARE YOU');
    console.log(this.animalForm.value);

    if (this.animalForm.value) {
      console.log(this.animalForm.value);
      const res = this.api.createAnimal(this.animalForm.value);
      console.log(res, 'Data Added Successfully');
      // this.animalForm.reset();
      // this.successMsg = res.message;
      // this.getAlldata();
    } else {
      this.errMsg = 'All Fields Are Required';
    }
  }

  updateAnimal() {
    console.log('update animal function in component??');
    console.log(this.animalForm.value);
    if (this.animalForm.value) {
      const res = this.api.updateData(this.animalForm.value, this.getparamid);
      console.log(res, 'Data Updated Successfully');
      // this.successMsg = res.message;
      // this.getAlldata();
    } else {
      this.errMsg = 'All Fields Are Required';
    }
  }
}

I saw a few other people use a function createGroup(), or other formats, they don’t work. A lot of the problem is people forgot to import the FormsModule and such, but I did. Still doesn’t work, am I just missing something? I am also using ng Build, not serve. It’s client sided. This code worked for my ng serve but I was asked to do it this way. So I restart everything and it still doesn’t love it.

New contributor

Anna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật