Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

angular - Ionic表示无法绑定到“ formGroup”,因为它不是“ form”的已知属性(Ionic says Can't bind to 'formGroup' since it isn't a known property of 'form')

I have a product-details page, in which I am using another child component product-card.

(我有一个产品详细信息页面,其中使用了另一个子组件产品卡。)

I have imported form module and reactive forms module on both the module files ie product-card.module.ts and product-details.module.ts.

(我已经在两个模块文件(即product-card.module.ts和product-details.module.ts)上导入了表单模块和反应形式模块。)

Still facing the error :(.

(仍然面临错误:(。)

this is product-details.module.ts

(这是product-details.module.ts)

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    ReactiveFormsModule,
    IonicModule,
    ProductDetailsPageRoutingModule,
    ProductCardModule
  ],
  declarations: [ProductDetailsPage],
  exports: [
    FormsModule,
    ReactiveFormsModule,
    ProductCardModule
  ]
})
export class ProductDetailsPageModule {}

This is product-card.module.ts

(这是product-card.module.ts)

@NgModule({
  imports: [
    CommonModule,
    MaterialModule,
    FormsModule,
    ReactiveFormsModule
  ]
})
export class ProductCardModule { }

This is product-card.component.ts where I am using form.

(这是我正在使用表单的product-card.component.ts。)

  constructor(private shoppingService: ShoppingService, private cart: CartService) {
    this.quantityForm = new FormGroup({
      quantity: new FormControl('', [
        Validators.required
      ])
    });
  }

I am very new at lazy loading in angular and I understand that is where I am missing something.

(我对angular的延迟加载非常陌生,我知道那是我缺少的东西。)

Ionic version is 4 and angular is 8. Thanks.

(离子版本为4,角度版本为8。谢谢。)

  ask by Aditya Thakur translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It should be like on html

(它应该像在html上一样)

<form [formGroup]="quantityForm">
// your code
</form>

On your product-card.component.ts file, firstly before constructor

(在product-card.component.ts文件上,首先在构造函数之前)

quantityForm : FormGroup;

then you should write the constructor code.

(那么您应该编写构造函数代码。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...