简体   繁体   中英

inject() must be called from an injection context on angular

after update angular 13, the project is running - but error accourd: "inject() must be called from an injection context". The project has lazy loading module. How can I know what caused the problem? Maybe I have to change something on services? Mabye the problem is on Lazy Loading Modules? package.json

   "name": "angular",
   "version": "0.0.0",
   "scripts": {
     "ng": "ng",
     "start": "ng serve",
     "build": "ng build",
     "test": "ng test",
     "lint": "ng lint",
     "e2e": "ng e2e"
   },
   "private": true,
   "dependencies": {
     "@angular/animations": "^13.2.1",
     "@angular/cdk": "^12.2.13",
     "@angular/common": "^13.2.1",
     "@angular/compiler": "^13.2.1",
     "@angular/core": "^13.2.1",
     "@angular/forms": "^13.2.1",
     "@angular/material": "^12.2.13",
     "@angular/platform-browser": "^13.2.1",
     "@angular/platform-browser-dynamic": "^13.2.1",
     "@angular/router": "^13.2.1",
     "@ngx-translate/core": "^13.0.0",
     "@ngx-translate/http-loader": "^6.0.0",
     "@syncfusion/ej2-angular-grids": "^19.4.47",
     "@syncfusion/ej2-angular-navigations": "^19.4.47",
     "ag-grid-angular": "^26.2.0",
     "ag-grid-community": "^26.2.1",
     "ag-grid-enterprise": "^26.2.1",
     "angular-cli": "^1.0.0-beta.28.3",
     "angular-material": "^1.2.4",
     "blob-util": "^2.0.2",
     "bootstrap": "^4.6.1",
     "file-saver": "^2.0.5",
     "jquery": "^3.6.0",
     "material-icons": "^1.10.6",
     "ng-click-outside": "^8.0.0",
     "ngx-cookie-service": "^13.2.0",
     "ngx-take-until-destroy": "^5.4.0",
     "popper.js": "^1.16.1",
     "rxjs": "^6.6.7",
     "tslib": "^2.3.1",
     "zone.js": "~0.11.4"
   },
   "devDependencies": {
     "@angular-devkit/build-angular": "^13.2.2",
     "@angular/cli": "^13.2.2",
     "@angular/compiler-cli": "^13.2.1",
     "@angular/localize": "^13.2.1",
     "@types/file-saver": "^2.0.5",
     "@types/jasmine": "^3.6.11",
     "@types/jquery": "^3.5.13",
     "@types/node": "^12.20.42",
     "codelyzer": "^6.0.2",
     "jasmine-core": "~3.8.0",
     "jasmine-spec-reporter": "~5.0.0",
     "karma": "^6.3.12",
     "karma-chrome-launcher": "~3.1.0",
     "karma-coverage": "~2.0.3",
     "karma-jasmine": "~4.0.0",
     "karma-jasmine-html-reporter": "^1.7.0",
     "protractor": "~7.0.0",
     "ts-node": "~8.3.0",
     "tslint": "~6.1.0",
     "typescript": "^4.5.5",
     "webpack": "^5.68.0",
     "webpack-dev-server": "^4.7.4"
   }
 }```



You should add:

    @Injectable({
      providedIn: 'root'
    })
export class FooService

to all your generated services

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM