Angular无法解析所有参数

时间:2017-10-25 11:24:10

标签: angular angular-services

嗨我有角度Can't resolve all parameters for RoomService: (?).的错误我有这两个文件,就是服务。

room.service.ts

import { Injectable } from '@angular/core';
import { ResourceService } from './resource.service';
import { Http } from '@angular/http';
import { CONFIG as APP_CONSTANTS } from '../config/config';

@Injectable()
export class RoomService extends ResourceService {

  constructor(http) {
    super(http);
  }

}

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

// Angular Material
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MaterialComponents } from '../ngcomponents/material.component';

import { AppRoutingModule } from './app-routing.module';

// Components
import { AppComponent } from './app.component';
import { RoomlistComponent } from './components/roomlist/roomlist.component';

// services
import { HttpModule } from '@angular/http';
import { RoomService } from './services/room.service';

@NgModule({
  declarations: [
    AppComponent,
    RoomlistComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpModule,
    BrowserAnimationsModule,
    MaterialComponents
  ],
  providers: [RoomService],
  bootstrap: [AppComponent]
})
export class AppModule { }

并且我不知道问题是什么,任何想法,以防万一你可以看到RoomService从另一个文件resourceService扩展我不知道这是否是问题,但我不认为如此。

3 个答案:

答案 0 :(得分:2)

构造函数应具有http类型的Http参数。依赖解析器将通过它知道,他应该创建Http注入器的令牌。

constructor(http: Http) {
   super(http);
}

答案 1 :(得分:0)

Angular无法确定要传递的内容,因为http没有类型注释

constructor(http) {

如果您将其更改为

constructor(http:Http) {

并将HttpModule添加到imports: [...]的{​​{1}},它应该有效。 您还需要为AppModule添加TypeScript导入。

另见

答案 2 :(得分:0)

在你的roomService中,你DI应该是

 constructor(http: Http) {
    super(http);
  }
相关问题