我使用Angular2创建了自定义分页组件,但在尝试在另一个组件中使用它时,收到以下错误
Can't bind to 'offset' since it isn't a known property of 'app-pagination'.
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文件
<app-pagination [offset]="offset" [limit]="limit" [size]="count" (pageChange)="onPageChange($event)"></app-pagination>
@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() { }
}
您需要创建一个单独的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