【发布时间】:2019-10-08 03:02:14
【问题描述】:
我正在尝试将我的HTTP 服务注入另一个服务。我不确定我做错了什么,我不断收到错误
无法解析 GanttPropertyService 的所有参数:(?)。
这是我的服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/internal/Observable';
@Injectable({
providedIn: 'root'
})
export class HttpService {
constructor(private httpClient: HttpClient) {}
...
}
应用模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpService } from './services/shared/httpService';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpConfigInterceptor} from './services/shared/httpconfig.interceptor';
import {ErrorDialogService} from './services/shared/errorHandling/errorDialogueService'
import { GanttModule } from './gantt/gantt.module'
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
GanttModule,
],
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: HttpConfigInterceptor, multi: true },
HttpService,
ErrorDialogService,
],
bootstrap: [AppComponent]
})
export class AppModule { }
我正在尝试在GanttModule 中使用这个httpService
甘特模块
import { NgModule } from '@angular/core';
import { GanttComponent } from './gantt.component';
import { GanttPropertyService} from '../services/gantt/ganttPropertyService';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatToolbarModule, MatButtonModule, MatMenuModule, MatIconModule, MatDialogModule } from '@angular/material';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { GanttToolBar } from './ganttToolBar/ganttToolBar.component';
@NgModule({
declarations: [
GanttComponent,
GanttToolBar,
],
imports: [
FormsModule,
ReactiveFormsModule,
MatMenuModule,
MatToolbarModule, MatButtonModule, MatIconModule, BrowserAnimationsModule,
MatDialogModule
],
providers: [
GanttPropertyService,
]
})
export class GanttModule { }
这是我要注入的服务
import {HttpService} from '../shared/httpService';
export class GanttPropertyService{
constructor(private http : HttpService){}
}
如何在较低级别的模块中使用httpService?`
【问题讨论】:
-
我没有投反对票,但有几件事。如果您将
providedIn: 'root'用于该服务,则无需将HttpService添加到providers。还有@Injectable的GanttPropertyService在哪里?尝试将@Injectable({ providedIn: 'root' })添加到GanttPropertyService,如果这样可以解决问题,请告诉我们。
标签: angular dependency-injection