4
4
* The http module provides services to perform http requests. To get started, see the {@link Http}
5
5
* class.
6
6
*/
7
- import { bind , Binding } from 'angular2/core' ;
7
+ import { provide , Provider } from 'angular2/core' ;
8
8
import { Http , Jsonp } from './src/http/http' ;
9
9
import { XHRBackend , XHRConnection } from './src/http/backends/xhr_backend' ;
10
10
import { JSONPBackend , JSONPBackend_ , JSONPConnection } from './src/http/backends/jsonp_backend' ;
@@ -40,18 +40,18 @@ export {URLSearchParams} from './src/http/url_search_params';
40
40
/**
41
41
* Provides a basic set of injectables to use the {@link Http} service in any application.
42
42
*
43
- * The `HTTP_BINDINGS ` should be included either in a component's injector,
43
+ * The `HTTP_PROVIDERS ` should be included either in a component's injector,
44
44
* or in the root injector when bootstrapping an application.
45
45
*
46
46
* ### Example ([live demo](http://plnkr.co/edit/snj7Nv?p=preview))
47
47
*
48
48
* ```
49
49
* import {bootstrap, Component, NgFor, View} from 'angular2/angular2';
50
- * import {HTTP_BINDINGS , Http} from 'angular2/http';
50
+ * import {HTTP_PROVIDERS , Http} from 'angular2/http';
51
51
*
52
52
* @Component ({
53
53
* selector: 'app',
54
- * bindings : [HTTP_BINDINGS ]
54
+ * providers : [HTTP_PROVIDERS ]
55
55
* })
56
56
* @View ({
57
57
* template: `
@@ -83,11 +83,11 @@ export {URLSearchParams} from './src/http/url_search_params';
83
83
* .catch(err => console.error(err));
84
84
* ```
85
85
*
86
- * The primary public API included in `HTTP_BINDINGS ` is the {@link Http} class.
87
- * However, other bindings required by `Http` are included,
86
+ * The primary public API included in `HTTP_PROVIDERS ` is the {@link Http} class.
87
+ * However, other providers required by `Http` are included,
88
88
* which may be beneficial to override in certain cases.
89
89
*
90
- * The bindings included in `HTTP_BINDINGS ` include:
90
+ * The providers included in `HTTP_PROVIDERS ` include:
91
91
* * {@link Http}
92
92
* * {@link XHRBackend}
93
93
* * `BrowserXHR` - Private factory to create `XMLHttpRequest` instances
@@ -96,38 +96,38 @@ export {URLSearchParams} from './src/http/url_search_params';
96
96
*
97
97
* There may be cases where it makes sense to extend the base request options,
98
98
* such as to add a search string to be appended to all URLs.
99
- * To accomplish this, a new binding for {@link RequestOptions} should
100
- * be added in the same injector as `HTTP_BINDINGS `.
99
+ * To accomplish this, a new provider for {@link RequestOptions} should
100
+ * be added in the same injector as `HTTP_PROVIDERS `.
101
101
*
102
102
* ### Example ([live demo](http://plnkr.co/edit/aCMEXi?p=preview))
103
103
*
104
104
* ```
105
- * import {bind , bootstrap} from 'angular2/angular2';
106
- * import {HTTP_BINDINGS , BaseRequestOptions, RequestOptions} from 'angular2/http';
105
+ * import {provide , bootstrap} from 'angular2/angular2';
106
+ * import {HTTP_PROVIDERS , BaseRequestOptions, RequestOptions} from 'angular2/http';
107
107
*
108
108
* class MyOptions extends BaseRequestOptions {
109
109
* search: string = 'coreTeam=true';
110
110
* }
111
111
*
112
- * bootstrap(App, [HTTP_BINDINGS, bind (RequestOptions).toClass( MyOptions)])
112
+ * bootstrap(App, [HTTP_PROVIDERS, provide (RequestOptions, {asClass: MyOptions} )])
113
113
* .catch(err => console.error(err));
114
114
* ```
115
115
*
116
116
* Likewise, to use a mock backend for unit tests, the {@link XHRBackend}
117
- * binding should be bound to {@link MockBackend}.
117
+ * provider should be bound to {@link MockBackend}.
118
118
*
119
119
* ### Example ([live demo](http://plnkr.co/edit/7LWALD?p=preview))
120
120
*
121
121
* ```
122
- * import {bind , Injector} from 'angular2/angular2';
123
- * import {HTTP_BINDINGS , Http, Response, XHRBackend, MockBackend} from 'angular2/http';
122
+ * import {provide , Injector} from 'angular2/angular2';
123
+ * import {HTTP_PROVIDERS , Http, Response, XHRBackend, MockBackend} from 'angular2/http';
124
124
*
125
125
* var people = [{name: 'Jeff'}, {name: 'Tobias'}];
126
126
*
127
127
* var injector = Injector.resolveAndCreate([
128
- * HTTP_BINDINGS ,
128
+ * HTTP_PROVIDERS ,
129
129
* MockBackend,
130
- * bind (XHRBackend).toAlias( MockBackend)
130
+ * provide (XHRBackend, {asAlias: MockBackend} )
131
131
* ]);
132
132
* var http = injector.get(Http);
133
133
* var backend = injector.get(MockBackend);
@@ -150,34 +150,40 @@ export {URLSearchParams} from './src/http/url_search_params';
150
150
* });
151
151
* ```
152
152
*/
153
- export const HTTP_BINDINGS : any [ ] = [
153
+ export const HTTP_PROVIDERS : any [ ] = [
154
154
// TODO(pascal): use factory type annotations once supported in DI
155
155
// issue: https://github.com/angular/angular/issues/3183
156
- bind ( Http )
157
- . toFactory ( ( xhrBackend , requestOptions ) => { return new Http ( xhrBackend , requestOptions ) ; } ,
158
- [ XHRBackend , RequestOptions ] ) ,
156
+ provide ( Http ,
157
+ {
158
+ asFactory : ( xhrBackend , requestOptions ) => new Http ( xhrBackend , requestOptions ) ,
159
+ deps : [ XHRBackend , RequestOptions ]
160
+ } ) ,
159
161
BrowserXhr ,
160
- bind ( RequestOptions ) . toClass ( BaseRequestOptions ) ,
161
- bind ( ResponseOptions ) . toClass ( BaseResponseOptions ) ,
162
+ provide ( RequestOptions , { asClass : BaseRequestOptions } ) ,
163
+ provide ( ResponseOptions , { asClass : BaseResponseOptions } ) ,
162
164
XHRBackend
163
165
] ;
164
166
167
+ /**
168
+ * @deprecated
169
+ */
170
+ export const HTTP_BINDINGS = HTTP_PROVIDERS ;
165
171
166
172
/**
167
- * Provides a basic set of bindings to use the {@link Jsonp} service in any application.
173
+ * Provides a basic set of providers to use the {@link Jsonp} service in any application.
168
174
*
169
- * The `JSONP_BINDINGS ` should be included either in a component's injector,
175
+ * The `JSONP_PROVIDERS ` should be included either in a component's injector,
170
176
* or in the root injector when bootstrapping an application.
171
177
*
172
178
* ### Example ([live demo](http://plnkr.co/edit/vmeN4F?p=preview))
173
179
*
174
180
* ```
175
181
* import {Component, NgFor, View} from 'angular2/angular2';
176
- * import {JSONP_BINDINGS , Jsonp} from 'angular2/http';
182
+ * import {JSONP_PROVIDERS , Jsonp} from 'angular2/http';
177
183
*
178
184
* @Component ({
179
185
* selector: 'app',
180
- * bindings : [JSONP_BINDINGS ]
186
+ * providers : [JSONP_PROVIDERS ]
181
187
* })
182
188
* @View ({
183
189
* template: `
@@ -202,11 +208,11 @@ export const HTTP_BINDINGS: any[] = [
202
208
* }
203
209
* ```
204
210
*
205
- * The primary public API included in `JSONP_BINDINGS ` is the {@link Jsonp} class.
206
- * However, other bindings required by `Jsonp` are included,
211
+ * The primary public API included in `JSONP_PROVIDERS ` is the {@link Jsonp} class.
212
+ * However, other providers required by `Jsonp` are included,
207
213
* which may be beneficial to override in certain cases.
208
214
*
209
- * The bindings included in `JSONP_BINDINGS ` include:
215
+ * The providers included in `JSONP_PROVIDERS ` include:
210
216
* * {@link Jsonp}
211
217
* * {@link JSONPBackend}
212
218
* * `BrowserJsonp` - Private factory
@@ -215,37 +221,37 @@ export const HTTP_BINDINGS: any[] = [
215
221
*
216
222
* There may be cases where it makes sense to extend the base request options,
217
223
* such as to add a search string to be appended to all URLs.
218
- * To accomplish this, a new binding for {@link RequestOptions} should
219
- * be added in the same injector as `JSONP_BINDINGS `.
224
+ * To accomplish this, a new provider for {@link RequestOptions} should
225
+ * be added in the same injector as `JSONP_PROVIDERS `.
220
226
*
221
227
* ### Example ([live demo](http://plnkr.co/edit/TFug7x?p=preview))
222
228
*
223
229
* ```
224
- * import {bind , bootstrap} from 'angular2/angular2';
225
- * import {JSONP_BINDINGS , BaseRequestOptions, RequestOptions} from 'angular2/http';
230
+ * import {provide , bootstrap} from 'angular2/angular2';
231
+ * import {JSONP_PROVIDERS , BaseRequestOptions, RequestOptions} from 'angular2/http';
226
232
*
227
233
* class MyOptions extends BaseRequestOptions {
228
234
* search: string = 'coreTeam=true';
229
235
* }
230
236
*
231
- * bootstrap(App, [JSONP_BINDINGS, bind (RequestOptions).toClass( MyOptions)])
237
+ * bootstrap(App, [JSONP_PROVIDERS, provide (RequestOptions, {asClass: MyOptions} )])
232
238
* .catch(err => console.error(err));
233
239
* ```
234
240
*
235
241
* Likewise, to use a mock backend for unit tests, the {@link JSONPBackend}
236
- * binding should be bound to {@link MockBackend}.
242
+ * provider should be bound to {@link MockBackend}.
237
243
*
238
244
* ### Example ([live demo](http://plnkr.co/edit/HDqZWL?p=preview))
239
245
*
240
246
* ```
241
- * import {bind , Injector} from 'angular2/angular2';
242
- * import {JSONP_BINDINGS , Jsonp, Response, JSONPBackend, MockBackend} from 'angular2/http';
247
+ * import {provide , Injector} from 'angular2/angular2';
248
+ * import {JSONP_PROVIDERS , Jsonp, Response, JSONPBackend, MockBackend} from 'angular2/http';
243
249
*
244
250
* var people = [{name: 'Jeff'}, {name: 'Tobias'}];
245
251
* var injector = Injector.resolveAndCreate([
246
- * JSONP_BINDINGS ,
252
+ * JSONP_PROVIDERS ,
247
253
* MockBackend,
248
- * bind (JSONPBackend).toAlias( MockBackend)
254
+ * provide (JSONPBackend, {asAlias: MockBackend} )
249
255
* ]);
250
256
* var jsonp = injector.get(Jsonp);
251
257
* var backend = injector.get(MockBackend);
@@ -268,15 +274,21 @@ export const HTTP_BINDINGS: any[] = [
268
274
* });
269
275
* ```
270
276
*/
271
- export const JSONP_BINDINGS : any [ ] = [
277
+ export const JSONP_PROVIDERS : any [ ] = [
272
278
// TODO(pascal): use factory type annotations once supported in DI
273
279
// issue: https://github.com/angular/angular/issues/3183
274
- bind ( Jsonp )
275
- . toFactory (
276
- ( jsonpBackend , requestOptions ) => { return new Jsonp ( jsonpBackend , requestOptions ) ; } ,
277
- [ JSONPBackend , RequestOptions ] ) ,
280
+ provide ( Jsonp ,
281
+ {
282
+ asFactory : ( jsonpBackend , requestOptions ) => new Jsonp ( jsonpBackend , requestOptions ) ,
283
+ deps : [ JSONPBackend , RequestOptions ]
284
+ } ) ,
278
285
BrowserJsonp ,
279
- bind ( RequestOptions ) . toClass ( BaseRequestOptions ) ,
280
- bind ( ResponseOptions ) . toClass ( BaseResponseOptions ) ,
281
- bind ( JSONPBackend ) . toClass ( JSONPBackend_ )
286
+ provide ( RequestOptions , { asClass : BaseRequestOptions } ) ,
287
+ provide ( ResponseOptions , { asClass : BaseResponseOptions } ) ,
288
+ provide ( JSONPBackend , { asClass : JSONPBackend_ } )
282
289
] ;
290
+
291
+ /**
292
+ * @deprecated
293
+ */
294
+ export const JSON_BINDINGS = JSONP_PROVIDERS ;
0 commit comments