@ -91,7 +91,7 @@ export class MockConnection implements Connection {
|
||||
/**
|
||||
* A mock backend for testing the {@link Http} service.
|
||||
*
|
||||
* This class can be injected in tests, and should be used to override bindings
|
||||
* This class can be injected in tests, and should be used to override providers
|
||||
* to other backends, such as {@link XHRBackend}.
|
||||
*
|
||||
* #Example
|
||||
@ -102,9 +102,9 @@ export class MockConnection implements Connection {
|
||||
* var connection;
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* MockBackend,
|
||||
* bind(Http).toFactory((backend, defaultOptions) => {
|
||||
* provide(Http, {asFactory: (backend, defaultOptions) => {
|
||||
* return new Http(backend, defaultOptions)
|
||||
* }, [MockBackend, DefaultOptions])]);
|
||||
* }, deps: [MockBackend, DefaultOptions]})]);
|
||||
* var http = injector.get(Http);
|
||||
* var backend = injector.get(MockBackend);
|
||||
* //Assign any newly-created connection to local variable
|
||||
@ -137,9 +137,9 @@ export class MockBackend implements ConnectionBackend {
|
||||
* var text; //this will be set from mock response
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* MockBackend,
|
||||
* bind(Http).toFactory(backend, options) {
|
||||
* provide(Http, {asFactory: (backend, options) {
|
||||
* return new Http(backend, options);
|
||||
* }, [MockBackend, BaseRequestOptions]]);
|
||||
* }, deps: [MockBackend, BaseRequestOptions]}]);
|
||||
* var backend = injector.get(MockBackend);
|
||||
* var http = injector.get(Http);
|
||||
* backend.connections.subscribe(c => connection = c);
|
||||
|
@ -91,13 +91,13 @@ export class XHRConnection implements Connection {
|
||||
* #Example
|
||||
*
|
||||
* ```
|
||||
* import {Http, MyNodeBackend, HTTP_BINDINGS, BaseRequestOptions} from 'angular2/http';
|
||||
* import {Http, MyNodeBackend, HTTP_PROVIDERS, BaseRequestOptions} from 'angular2/http';
|
||||
* @Component({
|
||||
* viewBindings: [
|
||||
* HTTP_BINDINGS,
|
||||
* bind(Http).toFactory((backend, options) => {
|
||||
* viewProviders: [
|
||||
* HTTP_PROVIDERS,
|
||||
* provide(Http, {asFactory: (backend, options) => {
|
||||
* return new Http(backend, options);
|
||||
* }, [MyNodeBackend, BaseRequestOptions])]
|
||||
* }, deps: [MyNodeBackend, BaseRequestOptions]})]
|
||||
* })
|
||||
* class MyComponent {
|
||||
* constructor(http:Http) {
|
||||
|
@ -117,15 +117,15 @@ export class RequestOptions {
|
||||
* ### Example ([live demo](http://plnkr.co/edit/LEKVSx?p=preview))
|
||||
*
|
||||
* ```typescript
|
||||
* import {bind, bootstrap} from 'angular2/angular2';
|
||||
* import {HTTP_BINDINGS, Http, BaseRequestOptions, RequestOptions} from 'angular2/http';
|
||||
* import {provide, bootstrap} from 'angular2/angular2';
|
||||
* import {HTTP_PROVIDERS, Http, BaseRequestOptions, RequestOptions} from 'angular2/http';
|
||||
* import {App} from './myapp';
|
||||
*
|
||||
* class MyOptions extends BaseRequestOptions {
|
||||
* search: string = 'coreTeam=true';
|
||||
* }
|
||||
*
|
||||
* bootstrap(App, [HTTP_BINDINGS, bind(RequestOptions).toClass(MyOptions)]);
|
||||
* bootstrap(App, [HTTP_PROVIDERS, provide(RequestOptions, {asClass: MyOptions})]);
|
||||
* ```
|
||||
*
|
||||
* The options could also be extended when manually creating a {@link Request}
|
||||
|
@ -115,15 +115,16 @@ export class ResponseOptions {
|
||||
* ### Example ([live demo](http://plnkr.co/edit/qv8DLT?p=preview))
|
||||
*
|
||||
* ```typescript
|
||||
* import {bind, bootstrap} from 'angular2/angular2';
|
||||
* import {HTTP_BINDINGS, Headers, Http, BaseResponseOptions, ResponseOptions} from 'angular2/http';
|
||||
* import {provide, bootstrap} from 'angular2/angular2';
|
||||
* import {HTTP_PROVIDERS, Headers, Http, BaseResponseOptions, ResponseOptions} from
|
||||
* 'angular2/http';
|
||||
* import {App} from './myapp';
|
||||
*
|
||||
* class MyOptions extends BaseResponseOptions {
|
||||
* headers:Headers = new Headers({network: 'github'});
|
||||
* }
|
||||
*
|
||||
* bootstrap(App, [HTTP_BINDINGS, bind(ResponseOptions).toClass(MyOptions)]);
|
||||
* bootstrap(App, [HTTP_PROVIDERS, provide(ResponseOptions, {asClass: MyOptions})]);
|
||||
* ```
|
||||
*
|
||||
* The options could also be extended when manually creating a {@link Response}
|
||||
|
@ -39,8 +39,8 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
|
||||
* #Example
|
||||
*
|
||||
* ```typescript
|
||||
* import {Http, HTTP_BINDINGS} from 'angular2/http';
|
||||
* @Component({selector: 'http-app', viewBindings: [HTTP_BINDINGS]})
|
||||
* import {Http, HTTP_PROVIDERS} from 'angular2/http';
|
||||
* @Component({selector: 'http-app', viewProviders: [HTTP_PROVIDERS]})
|
||||
* @View({templateUrl: 'people.html'})
|
||||
* class PeopleComponent {
|
||||
* constructor(http: Http) {
|
||||
@ -63,7 +63,7 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
|
||||
*
|
||||
* The default construct used to perform requests, `XMLHttpRequest`, is abstracted as a "Backend" (
|
||||
* {@link XHRBackend} in this case), which could be mocked with dependency injection by replacing
|
||||
* the {@link XHRBackend} binding, as in the following example:
|
||||
* the {@link XHRBackend} provider, as in the following example:
|
||||
*
|
||||
* #Example
|
||||
*
|
||||
@ -72,11 +72,11 @@ function mergeOptions(defaultOpts, providedOpts, method, url): RequestOptions {
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* BaseRequestOptions,
|
||||
* MockBackend,
|
||||
* bind(Http).toFactory(
|
||||
* provide(Http, {asFactory:
|
||||
* function(backend, defaultOptions) {
|
||||
* return new Http(backend, defaultOptions);
|
||||
* },
|
||||
* [MockBackend, BaseRequestOptions])
|
||||
* deps: [MockBackend, BaseRequestOptions]})
|
||||
* ]);
|
||||
* var http = injector.get(Http);
|
||||
* http.get('request-from-mock-backend.json').subscribe((res:Response) => doSomething(res));
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Index to be used if Http is ever configured as a standalone npm package.
|
||||
// require('reflect-metadata');
|
||||
// require('es6-shim');
|
||||
// import {HTTP_BINDINGS, JSONP_BINDINGS, Http, Jsonp} from './http';
|
||||
// import {HTTP_PROVIDERS, JSONP_PROVIDERS, Http, Jsonp} from './http';
|
||||
// import {Injector} from 'angular2/angular2';
|
||||
// export * from './http';
|
||||
|
||||
@ -9,5 +9,5 @@
|
||||
// * TODO(jeffbcross): export each as their own top-level file, to require as:
|
||||
// * require('angular2/http'); require('http/jsonp');
|
||||
// */
|
||||
// export var http = Injector.resolveAndCreate([HTTP_BINDINGS]).get(Http);
|
||||
// export var jsonp = Injector.resolveAndCreate([JSONP_BINDINGS]).get(Jsonp);
|
||||
// export var http = Injector.resolveAndCreate([HTTP_PROVIDERS]).get(Http);
|
||||
// export var jsonp = Injector.resolveAndCreate([JSONP_PROVIDERS]).get(Jsonp);
|
||||
|
@ -26,7 +26,7 @@ import {
|
||||
*
|
||||
* ```typescript
|
||||
* import {Injectable, Injector} from 'angular2/angular2';
|
||||
* import {HTTP_BINDINGS, Http, Request, RequestMethods} from 'angular2/http';
|
||||
* import {HTTP_PROVIDERS, Http, Request, RequestMethods} from 'angular2/http';
|
||||
*
|
||||
* @Injectable()
|
||||
* class AutoAuthenticator {
|
||||
@ -40,7 +40,7 @@ import {
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* var injector = Injector.resolveAndCreate([HTTP_BINDINGS, AutoAuthenticator]);
|
||||
* var injector = Injector.resolveAndCreate([HTTP_PROVIDERS, AutoAuthenticator]);
|
||||
* var authenticator = injector.get(AutoAuthenticator);
|
||||
* authenticator.request('people.json').subscribe(res => {
|
||||
* //URL should have included '?password=123'
|
||||
|
Reference in New Issue
Block a user