Error: NG0203: inject() must be called from an injection context

Discussão em 'Angular' iniciado por Lisa Karner, Março 4, 2025.

  1. Lisa Karner

    Lisa Karner Guest

    In my Angular and Bootstrap project, I implementet a table according to bootstrap documentation. Since i added Pagination to the table i get the error-message following error message:

    ERROR Error: NG0203: inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.io/errors/NG0203 Angular 4 RuntimeError injectInjectorOnly
    _NgbPagination ng-bootstrap.mjs:11264


    Without the Pagnination my code works.

    <ngb-pagination
    [collectionSize]="collectionSize"
    [(page)]="page"
    [pageSize]="pageSize"
    (pageChange)="refreshCountries()"
    >
    </ngb-pagination>


    I checked if i have the right bootstrap and angular version and if i have Importet everything i need:


    import {Component } from '@angular/core';
    import { DecimalPipe } from '@angular/common';
    import { FormsModule } from '@angular/forms';
    import { NgbPaginationModule, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
    import { CommonModule } from '@angular/common';
    import { Geschlecht, Kandidat } from '../../model/kandidat';
    import { KandidatService } from '../../service/kandidat.service';
    @Component({
    selector: 'app-kandidatenliste',
    imports: [CommonModule,DecimalPipe, FormsModule, NgbTypeaheadModule, NgbPaginationModule],
    templateUrl: './kandidatenliste.component.html',
    styleUrl: './kandidatenliste.component.scss'
    })

    Continue reading...

Compartilhe esta Página