我试图使用angular2 http请求,但我收到以下错误:[错误]例外:没有ConnectionBackend的提供程序!(AppComponent - > Http - > ConnectionBackend)
我已经设置了一个具有相同问题的准系统应用程序,并且对导致它的原因感到茫然.
提前致谢
app.component.ts
import {Component} from 'angular2/core';
import {Http, Headers} from 'angular2/http';
@Component({
selector: 'app',
template: `
<button (click)="getEmployee()">Get</button>
<p>{{employee.email}}</p>
`,
providers: [Http]
})
export class AppComponent {
employee: {"email": "bob"};
http: Http;
constructor(http:Http){
this.http = http;
}
getEmployee(){
this.http.get('localhost:8080/employee-rates?id=0')
.map(response => response.json()).subscribe(result => this.employee = result);
}
}
Run Code Online (Sandbox Code Playgroud)
main.ts
import {AppComponent} from './app.component';
import {bootstrap} from 'angular2/platform/browser';
import {HTTP_PROVIDERS, HTTP_BINDINGS} from 'angular2/http';
bootstrap(AppComponent, [
HTTP_PROVIDERS, HTTP_BINDINGS
]);
Run Code Online (Sandbox Code Playgroud)
的index.html
<html>
<head>
<base …Run Code Online (Sandbox Code Playgroud)