gpt4 book ai didi

javascript - 错误 : StaticInjectorError(AppModule)[PaginationComponent -> PaginationConfig]

转载 作者:行者123 更新时间:2023-11-30 14:02:17 27 4
gpt4 key购买 nike

我正尝试按照此链接中的说明向我的 Angular 应用程序添加分页:

Go to "Content switching"

我这样做了:

app.module.ts 中:

import { PaginationModule } from 'ngx-bootstrap/pagination';

@NgModule({
imports: [
@NgModule({
]
})

app.component.html 中:

<div class="container">
<div class="row">
<div class="row">
<div class="col-xs-12 col-12">
<div class="content-wrapper">
<p class="content-item" *ngFor="let content of returnedArray">{{content}}</p>
</div>
<pagination [totalItems]="contentArray.length" (pageChanged)="pageChanged($event)"></pagination>
</div>
</div>
</div>
</div>

app.component.ts 中:

import { Component, OnInit, Injectable } from '@angular/core';
import { PageChangedEvent } from 'ngx-bootstrap/pagination';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
@Injectable({
providedIn: 'root'
})
export class AppComponent implements OnInit {

contentArray = new Array(90).fill('');
returnedArray: string[];

ngOnInit(): void {
this.contentArray = this.contentArray.map((v: string, i: number)
=> `Content line ${i + 1}`);
this.returnedArray = this.contentArray.slice(0, 10);
}

pageChanged(event: PageChangedEvent): void {
const startItem = (event.page - 1) * event.itemsPerPage;
const endItem = event.page * event.itemsPerPage;
this.returnedArray = this.contentArray.slice(startItem, endItem);
}
}

但是当我编译时出现以下错误:

core.js:15724 ERROR Error: Uncaught (in promise): Error: StaticInjectorError(RootModule)[PaginationComponent -> PaginationConfig]: StaticInjectorError(Platform: core)[PaginationComponent -> PaginationConfig]: NullInjectorError: No provider for PaginationConfig! Error: StaticInjectorError(RootModule)[PaginationComponent -> PaginationConfig]: StaticInjectorError(Platform: core)[PaginationComponent -> PaginationConfig]: NullInjectorError: No provider for PaginationConfig! at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:8896) at resolveToken (core.js:9141) at tryResolveToken (core.js:9085)

知道哪里出了问题吗?

最佳答案

应该是这样吧?

import { PaginationModule } from 'ngx-bootstrap';

@NgModule({
imports: [PaginationModule.forRoot(),...]
})

关于javascript - 错误 : StaticInjectorError(AppModule)[PaginationComponent -> PaginationConfig],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56128456/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com