Angular 9- 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다.

남자

내 코드 환경은 Angular 9이며 반응 양식을 설정할 때 다음 오류가 발생했습니다.

오류 NG8002 : 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다.

Google과 StackOverflow에서 몇 가지 연구를 수행했지만 Angular 9를 사용하여 동일한 질문을 찾을 수 없지만 다른 게시물 제안을 기반으로 ReactiveFormsModule을 app.module.ts, routing.module.ts 및 recipe-로 가져옵니다. edit.component.spec.ts 파일. 그러나 오류가 계속 나타납니다. 내 코드를 첨부하면 누군가 나에게 제안 할 수 있습니까?

app.module.ts

import { RecipeService } from './recipes/recipe.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule} from '@angular/forms';

import { RoutingModule } from './routing.module';
import { ShoppingListService } from './shopping-list/shopping-list.service';
import { AppComponent } from './app.component';
import { RecipesComponent } from './recipes/recipes.component';
import { RecipeListComponent } from './recipes/recipe-list/recipe-list.component';
import { RecipeItemComponent } from './recipes/recipe-list/recipe-item/recipe-item.component';
import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
import { HeaderComponent } from './header/header.component';
import { ShoppingListComponent } from './shopping-list/shopping-list.component';
import { ShoppingEditComponent } from './shopping-list/shopping-edit/shopping-edit.component';
import { DropdownDirective } from './shared/dropdown.directive';

@NgModule({
  declarations: [
    AppComponent,
    RecipesComponent,
    RecipeListComponent,
    RecipeItemComponent,
    RecipeDetailComponent,
    HeaderComponent,
    ShoppingListComponent,
    ShoppingEditComponent,
    DropdownDirective
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    RoutingModule
  ],
  providers: [ShoppingListService, RecipeService],
  bootstrap: [AppComponent]
})
export class AppModule { }

routing.module.ts

import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RecipeStartComponent } from './recipes/recipe-start/recipe-start.component';
import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { ShoppingListComponent } from './shopping-list/shopping-list.component';
import { RecipesComponent } from './recipes/recipes.component';
import { RecipeEditComponent } from './recipes/recipe-edit/recipe-edit.component';

const routes: Routes = [
  {path: '', redirectTo: '/recipes', pathMatch: 'full'},
  {path: 'recipes', component: RecipesComponent, children: [
    {path: '', component: RecipeStartComponent},
    {path: 'new', component: RecipeEditComponent},
    {path: ':id', component: RecipeDetailComponent},
    {path: ':id/edit', component: RecipeEditComponent}
  ]},
  {path: 'shopping-list', component: ShoppingListComponent}
  ];
@NgModule({
  imports: [RouterModule.forRoot(routes), FormsModule, ReactiveFormsModule],
  exports: [RouterModule]
})
export class RoutingModule {}

recipe-edit.component.ts

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { FormGroup, FormControl } from '@angular/forms';

import { RecipeService } from './../recipe.service';

@Component({
  selector: 'app-recipe-edit',
  templateUrl: './recipe-edit.component.html',
  styleUrls: ['./recipe-edit.component.css']
})
export class RecipeEditComponent implements OnInit {
  id: number;
  editMode = false;
  recipeForm: FormGroup;

  constructor(private route: ActivatedRoute, private recipeService: RecipeService) { }

  ngOnInit() {
    this.route.params
      .subscribe(
        (paras: Params) => {
          this.id = +paras.id;
          this.editMode = paras.id != null;
          this.initForm();
        }
      );
  }

  private initForm() {
    let name = '';
    let imagePath = '';
    let description = '';

    if (this.editMode) {
      const editRecipe = this.recipeService.getRecipe(this.id);
      name = editRecipe.name;
      imagePath = editRecipe.imagePath;
      description = editRecipe.desc;
    }

    this.recipeForm = new FormGroup({
      name: new FormControl(name),
      imagePath: new FormControl(imagePath),
      description: new FormControl(description)
    });
  }

  onSubmit() {
    console.log(this.recipeForm);
  }
}

recipe-edit.component.html

<div class="row">
  <div class="col-xs-12">
    <form (ngSubmit) = "onSubmit()" [formGroup] = "recipeForm" >
      <div class="row">
        <div class="col-xs-12">
          <button class="btn btn-success" type = "submit"> Save </button>
          <button class="btn btn-danger" type = "button"> Cancel </button>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12">
          <div class="form-group">
            <label for="name"> Recipe Name</label>
            <input
              type = "text"
              id = "name"
              formControlName="name"
              class="form-control">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12">
          <div class="form-group">
            <label for="imagePath"> Image URL </label>
            <input
              type = "text"
              id = "imagePath"
              formControlName="imagePath"
              class="form-control">
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12">
          <img src="" class="img-reponsive">
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12">
          <div class="form-group">
            <label for="description"> Description </label>
            <textarea
              type = "text"
              id = "description"
              formControlName="description"
              class="form-control"
              rows = "6"></textarea>
          </div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12">
          <div class="row">
            <div class="col-xs-8">
              <input
                type = "text"
                class = "form-control">
              </div>
              <div class="col-xs-2">
                <input
                type = "number"
                class = "form-control">
            </div>
            <div class="col-xs-2">
              <button class="btn btn-danger" type = "button"> X </button>
            </div>
          </div>
        </div>
      </div>
    </form>
  </div>
</div>

recipe-edit.component.spec.ts

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { RecipeEditComponent } from './recipe-edit.component';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';

describe('RecipeEditComponent', () => {
  let component: RecipeEditComponent;
  let fixture: ComponentFixture<RecipeEditComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ RecipeEditComponent ],
      imports: [ReactiveFormsModule, FormsModule]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(RecipeEditComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });
});
엘리아스 소아레스

RecipeEditComponentAppModule에 속하는 경우 RecipeEditComponentin 을 선언해야합니다 app.module.ts.

import { RecipeService } from './recipes/recipe.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule} from '@angular/forms';

import { RoutingModule } from './routing.module';
import { ShoppingListService } from './shopping-list/shopping-list.service';
import { AppComponent } from './app.component';
// Add following line:
import { RecipeEditComponent } from './recipes/recipe-edit/recipe-edit.component'; // add this
import { RecipesComponent } from './recipes/recipes.component';
import { RecipeListComponent } from './recipes/recipe-list/recipe-list.component';
import { RecipeItemComponent } from './recipes/recipe-list/recipe-item/recipe-item.component';
import { RecipeDetailComponent } from './recipes/recipe-detail/recipe-detail.component';
import { HeaderComponent } from './header/header.component';
import { ShoppingListComponent } from './shopping-list/shopping-list.component';
import { ShoppingEditComponent } from './shopping-list/shopping-edit/shopping-edit.component';
import { DropdownDirective } from './shared/dropdown.directive';

@NgModule({
  declarations: [
    AppComponent,
    RecipesComponent,
    RecipeEditComponent, // add this and the import line
    RecipeListComponent,
    RecipeItemComponent,
    RecipeDetailComponent,
    HeaderComponent,
    ShoppingListComponent,
    ShoppingEditComponent,
    DropdownDirective
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    RoutingModule
  ],
  providers: [ShoppingListService, RecipeService],
  bootstrap: [AppComponent]
})
export class AppModule { }

또 다른 모듈에 속하는 그렇지 않으면, 당신은 가져올 필요 FormsModule하고 ReactiveFormsModule이 속한 모듈.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Angular에서 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다.

분류에서Dev

오류 NG8002 : 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다. Angular 9에서

분류에서Dev

Angular Ivy : 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다. 그러나 ReactiveFormsModule 및 FormsModule은 가져옵니다.

분류에서Dev

각도 9 | 'img'의 알려진 속성이 아니므로 'loading'에 바인딩 할 수 없습니다.

분류에서Dev

Angular 10은 'option'의 알려진 속성이 아니므로 'ngForOf'에 바인딩 할 수 없습니다.

분류에서Dev

angular 11 'iframe'의 알려진 속성이 아니므로 'allow'에 바인딩 할 수 없습니다.

분류에서Dev

Angular 2- 'input'의 알려진 속성이 아니므로 'ngModel'에 바인딩 할 수 없습니다.

분류에서Dev

Angular2 : 'x'의 알려진 속성이 아니므로 'ngPluralCase'에 바인딩 할 수 없습니다.

분류에서Dev

Angular 2 * ngFor 오류 : 'div'의 알려진 속성이 아니므로 'menuitemtype'에 바인딩 할 수 없습니다.

분류에서Dev

'li'Angular 9의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

분류에서Dev

'mat-row'의 알려진 속성이 아니므로 'matRowDefColumns'에 바인딩 할 수 없습니다.

분류에서Dev

'ngx-datatable'의 알려진 속성이 아니므로 'rows'에 바인딩 할 수 없습니다.

분류에서Dev

'ng-container'의 알려진 속성이 아니므로 'ngForOf'에 바인딩 할 수 없습니다.

분류에서Dev

'app-details-upload'의 알려진 속성이 아니므로 'fileUpload'에 바인딩 할 수 없습니다.

분류에서Dev

콘솔 Angular 9의 경고 : 'li'의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

분류에서Dev

Angular 9에서 'tr'의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

분류에서Dev

'reddit'Angular2의 알려진 속성이 아니기 때문에 'article'에 바인딩 할 수 없습니다.

분류에서Dev

알려진 기본 속성이 아니므로 '값'에 바인딩 할 수 없습니다.

분류에서Dev

알려진 기본 속성이 아니므로 'href'에 바인딩 할 수 없습니다.

분류에서Dev

실패 : 템플릿 구문 분석 오류 : 'a'의 알려진 속성이 아니므로 'routerLink'에 바인딩 할 수 없습니다. ( "s ="navbar-nav ">

분류에서Dev

템플릿 구문 분석 오류 : 'input'의 알려진 속성이 아니므로 'ngbTypeahead'에 바인딩 할 수 없습니다.

분류에서Dev

Angular CLI : 'img'의 알려진 속성이 아니기 때문에 속성 'sip'에 바인딩 할 수 없습니다.

분류에서Dev

Angular는 알려진 속성이 아니기 때문에 'dirUnless'에 바인딩 할 수 없습니다.

분류에서Dev

이 오류가 발생하는 이유 : Angular 4에서 선택기 태그를 추가 할 때 'sebm-google-map'의 알려진 속성이 아니므로 'latitude'에 바인딩 할 수 없습니다.

분류에서Dev

'div'의 알려진 속성이 아니기 때문에 'cdkDragFreeDragPosition'에 바인딩 할 수 없습니다.

분류에서Dev

'input'의 알려진 속성이 아니기 때문에 'ng-model'에 바인딩 할 수 없습니다.

분류에서Dev

ngFor Angular에서 'li'의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

분류에서Dev

ionic2에서 요소 숨기기 : 알려진 기본 속성이 아니므로 '* ngIf'에 바인딩 할 수 없습니다.

분류에서Dev

EventEmitter-알려진 속성이 아니기 때문에 바인딩 할 수 없음-Angular 8

Related 관련 기사

  1. 1

    Angular에서 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다.

  2. 2

    오류 NG8002 : 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다. Angular 9에서

  3. 3

    Angular Ivy : 'form'의 알려진 속성이 아니므로 'formGroup'에 바인딩 할 수 없습니다. 그러나 ReactiveFormsModule 및 FormsModule은 가져옵니다.

  4. 4

    각도 9 | 'img'의 알려진 속성이 아니므로 'loading'에 바인딩 할 수 없습니다.

  5. 5

    Angular 10은 'option'의 알려진 속성이 아니므로 'ngForOf'에 바인딩 할 수 없습니다.

  6. 6

    angular 11 'iframe'의 알려진 속성이 아니므로 'allow'에 바인딩 할 수 없습니다.

  7. 7

    Angular 2- 'input'의 알려진 속성이 아니므로 'ngModel'에 바인딩 할 수 없습니다.

  8. 8

    Angular2 : 'x'의 알려진 속성이 아니므로 'ngPluralCase'에 바인딩 할 수 없습니다.

  9. 9

    Angular 2 * ngFor 오류 : 'div'의 알려진 속성이 아니므로 'menuitemtype'에 바인딩 할 수 없습니다.

  10. 10

    'li'Angular 9의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

  11. 11

    'mat-row'의 알려진 속성이 아니므로 'matRowDefColumns'에 바인딩 할 수 없습니다.

  12. 12

    'ngx-datatable'의 알려진 속성이 아니므로 'rows'에 바인딩 할 수 없습니다.

  13. 13

    'ng-container'의 알려진 속성이 아니므로 'ngForOf'에 바인딩 할 수 없습니다.

  14. 14

    'app-details-upload'의 알려진 속성이 아니므로 'fileUpload'에 바인딩 할 수 없습니다.

  15. 15

    콘솔 Angular 9의 경고 : 'li'의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

  16. 16

    Angular 9에서 'tr'의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

  17. 17

    'reddit'Angular2의 알려진 속성이 아니기 때문에 'article'에 바인딩 할 수 없습니다.

  18. 18

    알려진 기본 속성이 아니므로 '값'에 바인딩 할 수 없습니다.

  19. 19

    알려진 기본 속성이 아니므로 'href'에 바인딩 할 수 없습니다.

  20. 20

    실패 : 템플릿 구문 분석 오류 : 'a'의 알려진 속성이 아니므로 'routerLink'에 바인딩 할 수 없습니다. ( "s ="navbar-nav ">

  21. 21

    템플릿 구문 분석 오류 : 'input'의 알려진 속성이 아니므로 'ngbTypeahead'에 바인딩 할 수 없습니다.

  22. 22

    Angular CLI : 'img'의 알려진 속성이 아니기 때문에 속성 'sip'에 바인딩 할 수 없습니다.

  23. 23

    Angular는 알려진 속성이 아니기 때문에 'dirUnless'에 바인딩 할 수 없습니다.

  24. 24

    이 오류가 발생하는 이유 : Angular 4에서 선택기 태그를 추가 할 때 'sebm-google-map'의 알려진 속성이 아니므로 'latitude'에 바인딩 할 수 없습니다.

  25. 25

    'div'의 알려진 속성이 아니기 때문에 'cdkDragFreeDragPosition'에 바인딩 할 수 없습니다.

  26. 26

    'input'의 알려진 속성이 아니기 때문에 'ng-model'에 바인딩 할 수 없습니다.

  27. 27

    ngFor Angular에서 'li'의 알려진 속성이 아니기 때문에 'ngForOf'에 바인딩 할 수 없습니다.

  28. 28

    ionic2에서 요소 숨기기 : 알려진 기본 속성이 아니므로 '* ngIf'에 바인딩 할 수 없습니다.

  29. 29

    EventEmitter-알려진 속성이 아니기 때문에 바인딩 할 수 없음-Angular 8

뜨겁다태그

보관