小编Fai*_*br0的帖子

Angular2/http异常没有ConnectionBackend

我试图使用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)

service http angular

11
推荐指数
2
解决办法
2万
查看次数

标签 统计

angular ×1

http ×1

service ×1