【问题标题】:Issue in DataTable pagination multi selection for PrimeNG angular2PrimeNG angular2的DataTable分页多选问题
【发布时间】:2017-06-30 17:16:11
【问题描述】:

我在我的angular2 应用程序中使用primeng。我将DataTable 用于我的表格视图,当我尝试按照HERE 中的说明执行checkbox with paging 时,我遇到了错误...

错误...

Unhandled Promise rejection: Template parse errors:
Can't bind to 'headerCheckboxToggleAllPages' since it isn't a known property of 'p-dataTable'.
1. If 'p-dataTable' is an Angular component and it has 'headerCheckboxToggleAllPages' input, then verify that it is part of this module.
2. If 'p-dataTable' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message. [ERROR ->][headerCheckboxToggleAllPages]="true">
  <p-col"): ViewProductsComponent@22:36 ; Zone: <root> ; Task: Promise.then ; Value: SyntaxError Error: Template parse errors:

我是否需要为此导入任何特定模块,因为文档没有说明导入并且我遇到了类似的问题HERE并且在导入模块后它起作用了。

这是我的视图.html

<p-dataTable [value]="cars" [(selection)]="selectedCars3" [paginator]="true" [rows]="5" [headerCheckboxToggleAllPages]="true" sortMode="multiple" [selectionMode]="userRole=='user'? 'none' : 'single' ">
    <p-header>Checkbox Multiple Selection with Paging</p-header>
    <p-column [style]="{'width':'38px'}" selectionMode="multiple"></p-column>
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand"></p-column>
    <p-column field="color" header="Color"></p-column>
    <p-footer>
        <ul>
            <li *ngFor="let car of selectedCars3" style="text-align: left">{{car.vin + ' - ' + car.brand + ' - ' + car.year + ' - ' + car.color}}</li>
        </ul>
    </p-footer>
</p-dataTable>

和@NgModule.imports 是...

imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
routing,
DropdownModule,
DataTableModule,
DialogModule,
ConfirmDialogModule,
ContextMenuModule,
PanelModule,
OverlayPanelModule,
PanelMenuModule,
GrowlModule,
FileUploadModule,
InputSwitchModule,
TreeTableModule,
SharedModule,
CalendarModule,
ClipboardModule,
CommonModule,
SpinnerModule.forRoot(),
TabViewModule,
AutoCompleteModule
]

我的 package.json 依赖项...

"dependencies": {
    "@angular/common": "^2.3.1",
    "@angular/compiler": "^2.3.1",
    "@angular/core": "^2.3.1",
    "@angular/forms": "^2.3.1",
    "@angular/http": "^2.3.1",
    "@angular/platform-browser": "^2.3.1",
    "@angular/platform-browser-dynamic": "^2.3.1",
    "@angular/router": "^3.3.1",
    "primeng": "^2.0.1",
    "rxjs": "^5.0.1"
}

我也试过 pprimeng:4.1.0-rc.2 遇到同样的问题。请建议。谢谢

【问题讨论】:

  • 与 4.1.0 相同的错误?

标签: angular datatable primeng primeng-datatable


【解决方案1】:

你必须导入

import {DataTableModule,SharedModule} from 'primeng/primeng';

并在@NgModule.imports 中注册

【讨论】:

  • 我的@NgModule.imports 中有DataTableModule 和SharedModule 但仍然是同样的问题
  • 感谢您的宝贵时间,我已经添加了代码,请问是版本问题还是代码问题?谢谢
  • 更新primeng版本,看版本问题,headerCheckboxToggleAllPages是最新版本,更新到4.X.X。希望对你有帮助
  • 是的,我是这么认为的,并尝试了4.1.0-rc.2,所以最后提到了同样的事情
  • 这个版本是最后一个吗?
【解决方案2】:

目前尚不清楚错误背后的原因是什么,但您可以确定某些事情,例如 -

如果您在 package.json 中更改版本,要反映版本更改,您必须运行命令

npm install

更新依赖关系后,可以通过查看组件的定义文件来确认组件是否存在某些属性。例如在

中查找“headerCheckboxToggleAllPages”
node_modules\primeng\components\datatable\datatable.d.ts

希望这会有所帮助。

【讨论】:

  • 认为它是为angular 4 而不是angular 2
猜你喜欢
  • 1970-01-01
  • 2017-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-10
  • 2016-11-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多