feat(http): add support for JSONP requests

Closes #2905
Closes #2818
This commit is contained in:
Caitlin Potter
2015-07-14 19:53:04 -05:00
parent b4cde697b5
commit 81abc39929
21 changed files with 566 additions and 12 deletions

View File

@ -0,0 +1,11 @@
<!doctype html>
<html>
<title>Hello Jsonp</title>
<body>
<jsonp-app>
Loading...
</jsonp-app>
$SCRIPTS$
</body>
</html>

View File

@ -0,0 +1,12 @@
/// <reference path="../../../angular2/typings/rx/rx.all.d.ts" />
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {jsonpInjectables} from 'angular2/http';
import {JsonpCmp} from './jsonp_comp';
export function main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(JsonpCmp, [jsonpInjectables]);
}

View File

@ -0,0 +1,11 @@
<!doctype html>
<html>
<title>Angular 2.0 Jsonp (Reflection)</title>
<body>
<jsonp-app>
Loading...
</jsonp-app>
$SCRIPTS$
</body>
</html>

View File

@ -0,0 +1,13 @@
import {JsonpCmp} from './jsonp_comp';
import {bootstrap} from 'angular2/angular2';
import {reflector} from 'angular2/src/reflection/reflection';
import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities';
import {jsonpInjectables} from 'angular2/http';
export function main() {
// This entry point is not transformed and exists for testing purposes.
// See index.js for an explanation.
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(JsonpCmp, [jsonpInjectables]);
}

View File

@ -0,0 +1,23 @@
library examples.src.jsonp.jsonp_comp;
import "package:angular2/angular2.dart" show Component, View, NgFor;
import "package:angular2/http.dart" show Jsonp;
import "package:angular2/src/facade/async.dart" show ObservableWrapper;
@Component(selector: "jsonp-app")
@View(directives: const [NgFor], template: '''
<h1>people</h1>
<ul class="people">
<li *ng-for="#person of people">
hello, {{person[\'name\']}}
</li>
</ul>
''')
class JsonpCmp {
Object people;
JsonpCmp(Jsonp jsonp) {
ObservableWrapper.subscribe(
jsonp.get("./people.json?callback=JSONP_CALLBACK"),
(res) => this.people = res.json().toList());
}
}

View File

@ -0,0 +1,23 @@
import {Component, View, NgFor} from 'angular2/angular2';
import {Jsonp} from 'angular2/http';
import {ObservableWrapper} from 'angular2/src/facade/async';
@Component({selector: 'jsonp-app'})
@View({
directives: [NgFor],
template: `
<h1>people</h1>
<ul class="people">
<li *ng-for="#person of people">
hello, {{person['name']}}
</li>
</ul>
`
})
export class JsonpCmp {
people: Object;
constructor(jsonp: Jsonp) {
ObservableWrapper.subscribe(jsonp.get('./people.json?callback=JSONP_CALLBACK'),
res => this.people = res.json());
}
}

View File

@ -0,0 +1,2 @@
// This can only be requested once due to constant method name :(
__ng_jsonp__.__req0.finished([{"name":"caitp"}])