【发布时间】:2016-03-21 14:48:44
【问题描述】:
我阅读了一篇关于如何将 Http 服务注入 Angular2 应用程序的文章。
https://angular.io/docs/ts/latest/api/http/HTTP_PROVIDERS-let.html
import {HTTP_PROVIDERS, Http} from 'angular2/http';
@Component({
selector: 'app',
providers: [HTTP_PROVIDERS],
....
我以为 Http 服务已经包含在 HTTP_PROVIDERS 中了。 (如下,根据文件)。
"The providers included in HTTP_PROVIDERS include:
Http
XHRBackend
BrowserXHR - Private factory to create XMLHttpRequest instances
RequestOptions - Bound to BaseRequestOptions class
ResponseOptions - Bound to BaseResponseOptions class"
既然如此,那我们怎么还需要导入Http进去呢?我们只能这样做吗
import {HTTP_PROVIDERS} from 'angular2/http';
另一方面,更具体地说,我们可以将组件提供程序更改为
providers: [Http]?
或者在引导程序中,我们可以做bootstrap(app, [Http]) 吗?
【问题讨论】: