错误:这是我收到的错误,即使我已将提供程序添加到我的组件中。我无法获取我的错误是什么。这是我的所有文件
应用程序组件.ts、应用程序组件.html、carservice.ts。
我无法解决。
EXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: No provider for Response!
ORIGINAL STACKTRACE:
error: DI Exception
platform-browser.umd.js:962 Error: DI Exception
at NoProviderError.BaseException [as constructor] (core.umd.js:3776)
at NoProviderError.AbstractProviderError [as constructor] (core.umd.js:4307)
at new NoProviderError (core.umd.js:4342)
at ReflectiveInjector_._throwOrNull (core.umd.js:5794)
at ReflectiveInjector_._getByKeyDefault (core.umd.js:5822)
at ReflectiveInjector_._getByKey (core.umd.js:5785)
at ReflectiveInjector_.get (core.umd.js:5594)
at DebugAppView._View_IntegratedWorkshop_Host0.createInternal (IntegratedWorkshop_Host.template.js:29)
at DebugAppView.AppView.create (core.umd.js:9862)
at DebugAppView.create (core.umd.js:10054)
应用程序组件.ts
import {Component} from '@angular/core';
import {HTTP_PROVIDERS} from '@angular/http';
import {InputText,DataTable,Button,Dialog,Column,Header,Footer,Dropdown,SelectItem} from 'primeng/primeng';
import {CarService} from './cars/carservice';
@Component({
templateUrl: 'app/app.component.html',
selector: 'my-app',
directives: [InputText,DataTable,Button,Dialog,Column,Header,Footer,Dropdown],
providers: [HTTP_PROVIDERS,CarService]
})
export class AppComponent{
selectedCity: string;
cars: SelectItem[];
constructor(private carService: CarService) {
this.cars = [];
this.cars.push({label: "label", value: "value"});
}
ngOnInit() {
this.carService.getCarsMedium().then(cars => this.cars = cars);
}
}
应用程序组件.html:
<div >
<p-dropdown [options]="cars" [(ngModel)]="selectedCity"></p-dropdown>
<p>Selected City: {{selectedCity||'none'}}</p>
</div>
汽车服务.ts:
import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
@Injectable()
export class CarService {
constructor(private http: Http) {}
getCarsMedium() {
return this.http.get('app/resources/data/cars-medium.json')
.toPromise()
.then(res => <Car[]> res.json().data)
.then(data => { return data; });
}
}
export interface Car {
label;
value;
}
main.ts
import {bootstrap} from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import 'rxjs/Rx';
bootstrap(AppComponent);
汽车-medium.json
{
"data":[
{"label":"Mercedez", "value":"Mercedez"},
{"label":"BMW", "value":"BMW"},
{"label":"Lam", "value":"Lam"},
{"label":"Ista", "value":"Ista"},
{"label":"Ferrari", "value":"Ferrari"}
]
}