2017-08-10 98 views
0

重複的名字我一直在使用的角度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

如何從 '@角/ HTTP' 改變'進口{}的Http;''到進口{}的Http從'@ angular/http';'在你的服務中? –

回答

0

在你CompanySelectModule,您使用import { HttpModule } from '@angular/http'; 與小寫 'h' 然後在您的CompanySelectService,您使用import { HttpModule } from '@angular/Http';一個大寫的 'H'!

由於@Harry寧建議,試圖改變進口在CompanySelectService使用小寫 'h'

+0

Omg謝謝!兩個小時,無法找到錯誤 – Fransebas