我一直在使用角度4突然它在我做服务并在服务中注入Http
时提示我一个错误和警告,我相信问题实际上来自于警告:
./~/@angular/Http/@angular/http.es5.js
There are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem
with other case-semantic.
Use equal casing. Compare these module identifiers:
* /Users/centroagdigital/Documents/...ui/node_modules/@angular/Http/@angular/http.es5.js
Used by 1 module(s), i. e.
.../components/company-select/company-select.service.ts
实际错误是:
Error: No provider for Http!
at injectionError (core.es5.js:1169)
at noProviderError (core.es5.js:1207)
以下是我使用此模块的类:
company-select.module.ts
:
import { NgModule } from '@angular/core';
import { CompanySelect } from './company-select.component';
import { HttpModule } from '@angular/http';
// service
import { CompanySelectService } from './company-select.service'
@NgModule({
providers: [
CompanySelectService
],
declarations: [
CompanySelect
],
imports: [
HttpModule
],
exports: [
CompanySelect
]
})
export class CompanySelectModule { }
company-select.service.ts
:
import { Injectable } from '@angular/core';
import { Http } from '@angular/Http';
// models
import { Company } from './models/company.interface'
@Injectable()
export class CompanySelectService
{
constructor(private http : Http){}
getCompanies() // : Company[] not implemented yet
{
return "";
}
}
答案 0 :(得分:0)
在您的CompanySelectModule中,您使用import { HttpModule } from '@angular/http';
用小写' h'然后在您的CompanySelectService中,使用import { HttpModule } from '@angular/Http';
使用大写' H' !
正如@Harry Ninh建议的那样,尝试更改CompanySelectService中的导入以使用小写' h'