export JSONP_PROVIDERS : any[]
export JSONP_PROVIDERS : any[]
exported from angular2/http defined in angular2/http.ts (line 281)
Provides a basic set of providers to use the Jsonp service in any application.
The JSONP_PROVIDERS should be included either in a component's injector,
or in the root injector when bootstrapping an application.
Example (live demo)
The primary public API included in JSONP_PROVIDERS is the Jsonp class.
However, other providers required by Jsonp are included,
which may be beneficial to override in certain cases.
The providers included in JSONP_PROVIDERS include:
JsonpJSONPBackendBrowserJsonp- Private factoryRequestOptions- Bound toBaseRequestOptionsclassResponseOptions- Bound toBaseResponseOptionsclass
There may be cases where it makes sense to extend the base request options,
such as to add a search string to be appended to all URLs.
To accomplish this, a new provider for RequestOptions should
be added in the same injector as JSONP_PROVIDERS.
Example (live demo)
Likewise, to use a mock backend for unit tests, the JSONPBackend
provider should be bound to MockBackend.
Example (live demo)
import {provide, Injector} from 'angular2/core';
import {JSONP_PROVIDERS, Jsonp, Response, JSONPBackend} from 'angular2/http';
import {MockBackend} from 'angular2/http/testing';
var people = [{name: 'Jeff'}, {name: 'Tobias'}];
var injector = Injector.resolveAndCreate([
JSONP_PROVIDERS,
MockBackend,
provide(JSONPBackend, {useExisting: MockBackend})
]);
var jsonp = injector.get(Jsonp);
var backend = injector.get(MockBackend);
// Listen for any new requests
backend.connections.observer({
next: connection => {
var response = new Response({body: people});
setTimeout(() => {
// Send a response to the request
connection.mockRespond(response);
});
});
jsonp.get('people.json').observer({
next: res => {
// Response came from mock backend
console.log('first person', res.json()[0].name);
}
});