服务-1
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class HttpService {
constructor(
private http: HttpClient
) {
// do something with http
}
}
服务2
import { Injectable } from '@angular/core';
import{ HttpService } from './user-account/http.service'
@Injectable({
providedIn: 'root'
})
export class ServiceTwo{
http: HttpService;
constructor() {
this.http = new HttpService() ;
}
}
这不管用,因为
this.httpService = new HttpService()
所以我尝试了另一种方法:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class HttpService {
http: HttpClient;
constructor() {
this.http = new HttpClient();
}
}
服务2
import { Injectable } from '@angular/core';
import{ HttpService } from './user-account/http.service'
@Injectable({
providedIn: 'root'
})
export class ServiceTwo{
http: HttpService;
constructor() {
this.http = new HttpService() ;
// do something with http
}
}
这不起作用,因为
HttpService
需要一些论证。我不知道这场争论的细节。