I am following this fundamental tutorial on Angular about Http.
As one can see in the "Setup: Installing the module" section, they import the HttpClientModule as follow:
import {HttpClientModule} from '@angular/common/http';
When I try this in my project, I get the following error: "Cannot find module '@angular/common/http'".
I have tried importing the following module, as follow:
import { HttpModule } from '@angular/http';
And then my imports section:
imports: [
HttpModule
],
The problem now is, I cannot inject this HttpModule into my service object, and I get the following error: "Cannot find module HttpModule".
Here is my service class:
import { Injectable, OnInit } from '@angular/core';
//Custom Models
import { Feed } from '../Models/Feed';
@Injectable()
export class FeedsService {
constructor(private httpClient: HttpModule) {}
}
What am I doing wrong?
Update
All I should have done when I realized I could not import the module as per the tutorial, was to run the npm update
command, to update all my packages.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…