I'm just playing around with services in Angular for the first time and I get the following error:
ERROR TypeError: this.httpClientModule.get is not a function
my services file:
import { Injectable } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
@Injectable()
export class AlertsService {
constructor(
private httpClientModule: HttpClientModule
) {
//
}
getAlerts() {
console.warn(this.httpClientModule.get('api-data/alerts-data.json'));
}
}
component file:
import { Component, OnInit, } from '@angular/core';
import { AlertsService } from '../alerts.service'
@Component({
selector: 'at-alerts',
templateUrl: './alerts.component.html',
styleUrls: ['./alerts.component.scss'],
providers: [AlertsService]
})
export class AlertsComponentEdit implements OnInit {
constructor(
private alertsService: AlertsService
) {
//
}
ngOnInit() {
this.alertsService.getAlerts();
}
}
Mock data file (alerts-data.json):
[{
"id": 1,
"name": "Louis",
"gender": "male"
}, {
"id": 2,
"name": "Jenna",
"gender": "female"
}, {
"id": 3,
"name": "Tom",
"gender": "male"
}];
From what I can tell get along with other methods like post etc should exist in httpClientModule, any idea how to resolve this error?