使用角度2集成自定义分页组件时遇到问题

问题描述 投票:0回答:1

我使用Angular2创建了自定义分页组件,但在尝试在另一个组件中使用它时,收到以下错误

Can't bind to 'offset' since it isn't a known property of 'app-pagination'.

app.module.ts

 import { PaginationComponent } from './components/pagination.component';
import { ComplaintModule } from './pages/complaints/complaints.module';
    import { App } from './app.component';
        @NgModule({
          bootstrap: [App],
          declarations: [
            App,
            PaginationComponent
          ],
           imports: [ // import Angular's modules
           BrowserModule,
           ComplaintModule

          ]})
        export class AppModule {
          constructor(public appState: AppState) {
          }
        }

尝试集成以下html文件

complaints.html

<app-pagination [offset]="offset" [limit]="limit" [size]="count" (pageChange)="onPageChange($event)"></app-pagination> 

pagination.component.ts

@Component({
  selector: 'app-pagination',
  templateUrl: './pagination.component.html',
  styleUrls: ['./pagination.component.scss']
})
export class PaginationComponent implements OnInit, OnChanges {
  @Input() offset: number = 0;
  @Input() limit: number = 1;
  @Input() size: number = 1;
  @Input() range: number = 3;

constructor() { }
}
angular
1个回答
3
投票

您需要创建一个单独的qazxsw poi,以便在多个模块中使用qazxsw poi

shared.module.ts

SharedModule

complaint.module.ts

PaginationComponent

一些-other.module.ts

@NgModule({
    declarations: [
        PaginationComponent
    ],
    exports: [
        PaginationComponent
    ]
})
export class SharedModule { 
}

现在你应该能够在@NgModule({ imports: [ SharedModule, ... ] ... }) export class ComplaintModule { } @NgModule({ imports: [ SharedModule, ... ] ... }) export class SomeOtherModule { } 中使用PaginationComponent

© www.soinside.com 2019 - 2024. All rights reserved.