2

我想在我的 angular t 项目中使用MatPaginatorModule ,但出现错误:

无法绑定到“pageSize”,因为它不是“mat-paginator”的已知属性

1. 如果 'mat-paginator' 是一个 Angular 组件并且它有 'pageSize' 输入,那么验证它是这个模块的一部分。 …………………………………………………………………………

html

  <mat-paginator #paginator
             [pageSize]="10"
             [pageSizeOptions]="[5, 10, 20]"
             [showFirstLastButtons]="true">
   </mat-paginator>

我在 app.module.ts 中导入了模块

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { GlobalModule } from './global/global.module';
import { ProtectedModule} from './protetcted/protect-module.component';
import { AppRoutingModule } from './app.routing.module';
// import { MatTableModule } from '@angular/material/table';
import { MatPaginatorModule } from '@angular/material';

@NgModule({
  declarations: [
    AppComponent,

  ],
  imports: [
    BrowserModule,
    GlobalModule,
    ProtectedModule,
    AppRoutingModule,
    // MatTableModule,
    MatPaginatorModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我正在使用 angular5

包.json

   {
  "name": "eci",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "node app.js",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.10",
    "@angular/cdk": "^5.2.5",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/material": "^5.2.5",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "angular-font-awesome": "^3.1.2",
    "bootstrap": "^4.1.0",
    "cfenv": "^1.0.4",
    "core-js": "^2.4.1",
    "express": "^4.15.0",
    "font-awesome": "^4.7.0",
    "jquery": "^3.3.1",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "~1.7.2",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.3.1",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}
4

2 回答 2

0

如果在进行测试时出现错误,则需要在 test/spec 文件中导入。(app.component.spec.ts)

于 2019-12-06T21:04:17.207 回答
0

@Kumail,从您发布的片段来看,一切看起来都很好。

尽管仅在未链接所需模块时才会发生此错误。我能想到的唯一原因是,您可能在修改后没有保存app.module.ts文件。我确实按照所有步骤将 MatPaginatorModule 集成到测试项目中并且它有效。然后我嘲笑将该模块包含在app.module.ts但没有保存更改。这次我收到了您发布的错误。尝试保存,如果您在修改app.module.ts文件后可能会错过。

于 2018-04-30T09:51:45.733 回答