Angular2/http 异常没有 ConnectionBackend [英] Angular2/http Exception no ConnectionBackend
本文介绍了Angular2/http 异常没有 ConnectionBackend的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 angular2 http 请求,但出现以下错误:[错误] 例外:ConnectionBackend 没有提供程序!(AppComponent -> Http -> ConnectionBackend)
我已经设置了一个具有相同问题的准系统应用程序,但不知道是什么原因造成的.
提前致谢
app.component.ts
从'angular2/core'导入{Component};从 'angular2/http' 导入 {Http, Headers};@零件({选择器:'应用',模板:`<button(点击)="getEmployee()">获取</button><p>{{employee.email}}</p>`,提供者:[Http]})导出类 AppComponent {员工:{电子邮件":鲍勃"};http:http;构造函数(http:http){this.http = http;}获取员工(){this.http.get('localhost:8080/employee-rates?id=0').map(response => response.json()).subscribe(result => this.employee = result);}}
main.ts
import {AppComponent} from './app.component';从 'angular2/platform/browser' 导入 {bootstrap};从 'angular2/http' 导入 {HTTP_PROVIDERS, HTTP_BINDINGS};引导程序(应用程序组件,[HTTP_PROVIDERS、HTTP_BINDINGS]);
index.html
<头><base href="/"><title>测试</title><meta name="viewport" content="width=device-width, initial-scale=1"><script src="js/es6-shim/es6-shim.min.js"></script><script src="js/systemjs/dist/system-polyfills.js"></script><script src="js/angular2/bundles/angular2-polyfills.js"></script><script src="js/systemjs/dist/system.src.js"></script><script src="js/rxjs/bundles/Rx.js"></script><script src="js/angular2/bundles/angular2.dev.js"></script><script src="js/angular2/bundles/http.dev.js"></script><!-- 2.配置SystemJS--><脚本>系统配置({包:{应用程序: {格式:'注册',默认扩展名:'js'}}});System.import('app/main').then(null, console.error.bind(console));头部><!-- 3. 显示应用程序--><身体><app>正在加载...</app>