无法绑定到“选项”,因为它不是“ p-selectButton”的已知属性。 -ngx-formly

时间:2018-08-20 23:40:49

标签: angular primeng angular-formly

我在我的Angle 5应用程序中使用ngx-formly。我创建了共享模块,并使用了形式选择按钮组件来显示某些字段。以下是我面临的错误。谁能帮忙。

1. If 'p-selectButton' is an Angular component and it has 'options' input, then verify that it is part of this module.
2. If 'p-selectButton' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("
        <p-selectButton
          styleClass="formly-select-button-style"
          [ERROR ->][options]="selectButtonOptions | async" [dataKey]="dataKey" [optionLabel]="optionLabel"
          [fo"): ng:///SharedModule/FormlySelectButtonComponent.html@19:10
Can't bind to 'dataKey' since it isn't a known property of 'p-selectButton'.

注意:我已经在 Shared.module.ts 文件中声明了正式模块,如下所示

import {FormlyModule, FormlyFieldConfig } from '@ngx-formly/core';

以及进口

@NgModule({
  imports: [
    CommonModule,
    PanelModule,
    AccordionModule,
    MessagesModule,
    MessagesModule,
    MenuModule,
    ButtonModule,
    FormlyModule.forRoot({
      types: [
 { name: 'input', component: FormlyFieldInputComponent },
 { name: 'selectbutton', component: FormlySelectButtonComponent },
      ],

我的声明

declarations: [
    LoaderComponent,
    CollectionPanelBoxComponent,
    AccordionHeaderEmptyComponent,
    FormlySelectButtonComponent,
    FormlyFieldInputComponent
  ],

我的出口

exports: [
 AccordionHeaderEmptyComponent,
    FormlyModule

]

不确定我在做什么错。

1 个答案:

答案 0 :(得分:0)

最后,经过漫长的一天,我找到了答案。

步骤1:(如果使用共享模块)。确保已在三个位置导入了必要的模块。

在Shared.module.ts代码中:

import {
  AccordionModule,
  ButtonModule, // First declaration point 
  DataTableModule,
  SelectButtonModule,
} from 'primeng/primeng';

同一文件中的第二个声明点

@NgModule({
  imports: [
    CommonModule,
    InputTextModule,
    AccordionModule,
    ReactiveFormsModule,
    MenuModule,
    DataTableModule,
    ButtonModule, // second declaration point 
], 

第三个声明点:

exports: [
    CommonModule,
    ReactiveFormsModule,
    PanelModule,
    AccordionModule,
    LoaderComponent,
    MessagesModule,
    MenuModule,
    InputTextModule,
    ButtonModule, // third declaration point 
    DataTableModule,
    DropdownModule,
    CollectionPanelBoxComponent,
    AccordionHeaderEmptyComponent,
    FormlyModule
  ]

如果一切都如上所述声明。

第2步:

然后检查灌注文件。就我而言,我已使用

  

“ primeng”:“ ^ 4.3.0”,

注意:您必须使用按钮pButton代替

<button pButton type="button" label="Click" ></button>
<p-button label="Click" ></p-button>

这肯定会解决这个问题。希望它可以帮助某人。