Issue
I am trying to create a angular new app using 'ng new appname'. After creating the app, I was able to run the application. When I include a new service with constructor argument httpclient, I am facing an error as like "No Provider for _httpclient".
My error screen in console :
My code in service :
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class UserinfoService {
constructor(private htpsrvc : HttpClient) { }
public GetEmployees() : any
{
//return this.htpsrvc.get("https://localhost:44387/api/Home")
}
}
I had searched about the issue, and I found like there is no app.module.ts file in my folder structure.
I am not sure how did I miss the file app.module.ts, while creating the new application.
My angular version is 17 and node version is v18.18.2
Solution
You need to add providedHttpClient()
to the providers in your app.config.ts
Answered By - Matthieu Riegler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.