Thursday, January 22, 2026
HomeLanguagesAngularAngular Cannot find name ‘Inject’

Angular Cannot find name ‘Inject’

Error cannot find name Inject in angular; Through this tutorial, we will find a solution for error cannot find Inject in angular applications.

And we can also use this solution with angular versions like angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, and angular 14 to resolve error cannot find Inject module.

Angular Cannot find name ‘Inject’

Now, we can see the solution to error cannot find the name Inject in angular; is as follow:

First of all, import Inject from @angular/core from npm package; is as follows:

import { Inject } from '@angular/core';

Let’s see the example of how to import Inject from @angular/core from npm package; is as follows:

import { Component, OnInit, Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/common';
   
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
    
    port = '';
    
    /*------------------------------------------
    --------------------------------------------
    constructor
    --------------------------------------------
    --------------------------------------------*/
    constructor(@Inject(DOCUMENT) private document: any) { }
    
    /*------------------------------------------
    --------------------------------------------
    ngOnInit
    --------------------------------------------
    --------------------------------------------*/
    ngOnInit() {
        this.port = this.document.location.port;
        console.log(this.port);
    }
  
}

Conclusion

Through this tutorial, we have found a solution for the ‘error cannot find Inject in angular applications’ and fixed this error as well.

RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS