Angular 角形罐';无法解析所有参数
您好,我有一个错误,来自angularAngular 角形罐';无法解析所有参数,angular,angular-services,Angular,Angular Services,您好,我有一个错误,来自angular无法解析RoomService:(?)的所有参数。我有这两个文件,在服务上 客房服务.ts import { Injectable } from '@angular/core'; import { ResourceService } from './resource.service'; import { Http } from '@angular/http'; import { CONFIG as APP_CONSTANTS } from '../confi
无法解析RoomService:(?)的所有参数。
我有这两个文件,在服务上
客房服务.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);
}
}
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 { }
应用程序模块.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);
}
}
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是从另一个文件资源服务扩展而来的,我不知道这是否是问题,但我不这么认为。构造函数应该有
http
参数作为http
类型。依赖解析程序应该通过它来创建Http
injector的标记
constructor(http: Http) {
super(http);
}
Angular无法确定要传递什么,因为
http
没有类型注释
constructor(http) {
如果你把它改成
constructor(http:Http) {
并将HttpModule
添加到AppModule
的imports:[…]
,它应该可以工作。
您还需要为Http
添加类型脚本导入
另见
- 在客房服务中,您应该
constructor(http: Http) {
super(http);
}