没有HTTP提供者angular2 nativescripte

时间:2017-03-22 12:45:20

标签: angular2-nativescript

No provider for Http

我正在尝试在使用Http组件的组件中注入服务。当我尝试在服务中注入Http组件时,我收到上述错误。以下是模块的代码:

app.module.ts

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";

import { AppComponent } from "./app.component";

@NgModule({
  declarations: [AppComponent],
  bootstrap: [AppComponent],
  imports: [NativeScriptModule],
  schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}

这是我的app.component.ts

import { Component,OnInit } from "@angular/core";
import { VoitureService} from './voiture/voiture.service'


@Component({
  selector: "my-app",
 moduleId:module.id,
  templateUrl: './app.component.html',
  providers: [VoitureService]

})
export class AppComponent {
 voitures: voiture[];
    clients:voiture;
    req:string='1';
constructor(private postsService:VoitureService) {

  }
  ngOnInit(){
        this.postsService. getPosts(this.req)
            .subscribe(results => this.voitures=results );
    }

}
interface voiture{
    id:number;
    libelle:string;
    ref:string;
}

此代码为voiture.service.ts

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import { Observable as RxObservable } from "rxjs/Rx";


@Injectable()
export class VoitureService {
    constructor(private http:Http){

    }
    getPosts(req:string){
        return this.http.get("http://localhost:8590/I2S_AUTO_MOBILE/Implementation/Intervention/getAllVoiture/"+req)
        .map(res => res.json());
        //console.log("http://localhost:8590/I2S_AUTO_MOBILE/Implementation/Intervention/getAllVoiture/"+req)
    }

    getClient(IDV:string){
        return this.http.get("http://localhost:8590/I2S_AUTO_MOBILE/Implementation/Intervention/getClientVoiture/"+IDV)
        .map(res => res.json());
    }


}

我缺少什么?感谢?

0 个答案:

没有答案