ItSolutionStuff.com

Angular - Cannot find name 'Inject' - Solved

By Hardik Savani • May 2, 2024
Angular

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, angular 13, angular 14, angular 15, angular 16 and angular 17 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.

Solution:

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

Import Output:

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

Let's see bellow working code:

Example:

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);

}

}

I hope it can help you...

Tags: Angular
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to use HttpHeaders in Angular 13?

Read Now →

Angular Stripe Payment Gateway Integration Tutorial

Read Now →

How to Create/Generate QR Code in Angular 13?

Read Now →

Angular 13 Image Upload with Preview Tutorial

Read Now →

Angular 13 Reactive Forms Validation Tutorial Example

Read Now →

Angular Material Multi Select Dropdown with Chips Example

Read Now →

Angular Material Select Dropdown Change Event Example

Read Now →

Angular Get Current Date and Time Example

Read Now →

Angular Material Multi Select Dropdown Example

Read Now →

How to Remove Hash from URL in Angular?

Read Now →

Angular Material Mat-table Sticky Header Row Example

Read Now →

Angular Google Pie Chart Example

Read Now →