Angular – Cannot find name ‘Inject’ – Solved

In this tutorial, you will learn Cannot find name ‘Inject’ in angular. this example will help you angular error ts2304 cannot find name ‘Inject’. it’s simple example of angular cannot find Inject error. I would like to show you angular cannot find name Inject. you will do the following things for solve cannot find name Inject angular error.

You can use this solution with angular 8, angular 9, angular 10, angular 11, angular 12 and angular 13 version.

In this post, I will give you the solution of “Cannot find name ‘Inject'” in angular application. we need to import Inject from @angular/core library. so let’s see below the solution and full code.


let’s import Inject from @angular/core npm package, as bellow:

Import Output:

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

Let’s see bellow working code:


import { Component, OnInit, Inject, Injectable } from '@angular/core';

import { DOCUMENT } from '@angular/common';


selector: 'app-root',

templateUrl: './app.component.html',

styleUrls: ['./app.component.css']


export class AppComponent implements OnInit {

port = '';






constructor(@Inject(DOCUMENT) private document: any) { }






ngOnInit() {

this.port = this.document.location.port;




I hope it can help you….medrectangle-4-multi-155{border:none!important;display:block!important;float:none;line-height:0;margin-bottom:15px!important;margin-left:0!important;margin-right:0!important;margin-top:15px!important;max-width:100%!important;min-height:250px;min-width:300px;padding:0;text-align:center!important}

Leave a Comment