Unexpected value 'HttpClient' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation

I am getting this error when i am importing “HttpClient” to app.module.ts

import { HttpClient } from '@angular/common/http';

Please help me out of it.

Alternately, Please give me a ionic Sample project where HTTP GET request is properly demonstrated.

I doubt that, because an import is not a declaration in a module. Your problem lies within the app module itself, not with the import.

What will i import to make HTTP get requests ?

You’re not listening either to me or the error message. This has nothing to do with imports.

This error message is caused by including something that should be imported in declarations rather than imports in your app.module.ts.

So yep, the problem is caused by not correctly importing something.

Just thought I’d comment here in case someone else comes here from google. Wouldn’t want them incorrectly believing this doesn’t have anything to do with imports.

1 Like

I think there is some confusion here, perhaps due to the word “import” being used to describe two totally different things:

  1. The JavaScript import statement, used to combine code from different compilation units, much as the #include directive works in C.
  2. A property of NgModules named imports, which indicates which Angular modules reference one another for lazy loading purposes.

OP was asking about usage #1, which I said (and still believe) is not relevant to the error message. You seem to be talking about usage #2.

At the time this thread was created, I believe the proper place for putting HttpClient in an app module was providers. It definitely wasn’t declarations, which is for components.

In that spirit, the proper thing to do today is add HttpClientModule to the imports section of your AppModule.

This was the issue in my case. Angular newbie here got me good. Thanks