I have service1 depending on an other service2.
Service2 has one parameter in its constructor.
When declaring service2 in the constructor of service1 like this
constructor(private service : service2) {...}
I have the following error : An argument for service1 is not provided.
The solution here Angular 2: Inject Service to another service. (No provider error) consisting to put service2 in app.module providers work for my components but not for the service1. I steel have the error : an argument for 'service2' is not provided.
for more details :
Service2 :
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { BehaviorSubject, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ApiService {
baseUrl = "http://127.0.0.1:8000";
httpHeaders = new HttpHeaders({ 'Content-Type': 'application/json' })
dataSource: BehaviorSubject<any> = new BehaviorSubject([]);
list: Array<any> = [];
constructor(private http: HttpClient) {
}
...
}
service1 :
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { ApiService } from './api.service';
@Injectable({
providedIn: 'root'
})
export class FlowsheetEditorService {
//declarations ...
// httpHeaders = new HttpHeaders({ 'Content-Type': 'application/json' })
constructor(private api : ApiService) { ...}
}
In app module :
providers: [ApiService],
bootstrap: [AppComponent]
Do you know why and can you help?
I don't know if that matter but I put all my services in a folder in the /app folder.
Thank you