Skip to content

Commit 133295c

Browse files
committed
feat(http): introduce http sample
Closes #9
1 parent 924357d commit 133295c

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

src/app/angular2-playground.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<nav>
22
<a href="#/" id="hello-link">Hello World</a> |
3-
<a [routerLink]="['/NgUpgradeCmp']" id="upgrade-link">ngUpgrade</a>
3+
<a [routerLink]="['/NgUpgradeCmp']" id="upgrade-link">ngUpgrade</a> |
4+
<a [routerLink]="['/HttpSampleCmp']" id="upgrade-link">HTTP sample</a>
45
</nav>
56

67
<router-outlet></router-outlet>

src/app/angular2-playground.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77

88
import {HelloCmp} from './components/hello/hello';
99
import {NgUpgradeCmp} from './components/ng-upgrade/ng-upgrade';
10+
import {HttpSampleCmp} from './components/http-sample/http-sample';
1011

1112

1213
@Component({
@@ -18,7 +19,8 @@ import {NgUpgradeCmp} from './components/ng-upgrade/ng-upgrade';
1819
})
1920
@RouteConfig([
2021
new Route({ path: '/', component: HelloCmp, name: 'HelloCmp' }),
21-
new Route({ path: '/ng-upgrade', component: NgUpgradeCmp, name: 'NgUpgradeCmp' })
22+
new Route({ path: '/ng-upgrade', component: NgUpgradeCmp, name: 'NgUpgradeCmp' }),
23+
new Route({ path: '/http-sample', component: HttpSampleCmp, name: 'HttpSampleCmp' })
2224
])
2325
export class Angular2PlaygroundApp {
2426
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ul>
2+
<li *ngFor="#suggestion of suggestions">{{ suggestion.login }}</li>
3+
</ul>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
it,
3+
iit,
4+
describe,
5+
ddescribe,
6+
expect,
7+
inject,
8+
injectAsync,
9+
TestComponentBuilder,
10+
beforeEachProviders
11+
} from 'angular2/testing';
12+
import {provide} from 'angular2/core';
13+
import {HttpSampleCmp} from './http-sample';
14+
15+
16+
describe('HttpSample Component', () => {
17+
18+
beforeEachProviders(() => []);
19+
20+
21+
it('should ...', injectAsync([TestComponentBuilder], (tcb:TestComponentBuilder) => {
22+
return tcb.createAsync(HttpSampleCmp).then((fixture) => {
23+
fixture.detectChanges();
24+
});
25+
}));
26+
27+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {Component} from 'angular2/core';
2+
import {CORE_DIRECTIVES} from 'angular2/angular2';
3+
4+
import {Http, HTTP_PROVIDERS} from 'angular2/http';
5+
6+
import 'rxjs/add/operator/map';
7+
8+
@Component({
9+
selector: 'http-sample',
10+
templateUrl: 'app/components/http-sample/http-sample.html',
11+
providers: [HTTP_PROVIDERS],
12+
directives: [CORE_DIRECTIVES],
13+
pipes: []
14+
})
15+
export class HttpSampleCmp {
16+
suggestions;
17+
18+
constructor(private http: Http) {
19+
this.http.get('http://api.github.com/users/cironunes/orgs')
20+
.map((res) => res.json())
21+
.subscribe((res) => this.suggestions = res);
22+
}
23+
24+
}

src/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
<script src="vendor/systemjs/dist/system.src.js"></script>
77
<script src="vendor/angular2/bundles/angular2.dev.js"></script>
88
<script src="vendor/angular2/bundles/router.dev.js"></script>
9+
<script src="vendor/angular2/bundles/http.dev.js"></script>
910
{{content-for 'head'}}
1011
<script>
1112
System.config({
13+
map: {
14+
'rxjs' : 'vendor/rxjs'
15+
},
1216
packages: {
1317
app: {
1418
format: 'register',
1519
defaultExtension: 'js'
20+
},
21+
'rxjs': {
22+
defaultExtension: 'js'
1623
}
1724
}
1825
});

0 commit comments

Comments
 (0)