This repository has been archived by the owner on Dec 4, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97d73cc
commit 5001355
Showing
5 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
public/docs/_examples/rxjs/ts/app/heroes-filtered.component.1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// #docplaster | ||
// #docregion | ||
// #docregion operator-import | ||
import 'rxjs/add/operator/do'; | ||
import 'rxjs/add/operator/filter'; | ||
// #docregion operator | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { HeroService } from './hero.service'; | ||
import { Hero } from './hero'; | ||
|
||
@Component({ | ||
template: ` | ||
<h2>HEROES</h2> | ||
<ul class="items"> | ||
<li *ngFor="let hero of heroes"> | ||
<span class="badge">{{ hero.id }}</span> {{ hero.name }} | ||
</li> | ||
</ul> | ||
` | ||
}) | ||
export class HeroListComponent implements OnInit { | ||
heroes: Hero[]; | ||
|
||
constructor( | ||
private service: HeroService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.service.getHeroes() | ||
.do(heroes => { | ||
console.log(heroes.length); | ||
}) | ||
.filter(heroes => heroes.length > 2) | ||
.subscribe(heroes => this.heroes = heroes); | ||
} | ||
} | ||
// #enddocregion operator-import | ||
|
||
// #docregion import-all | ||
import 'rxjs/Rx'; | ||
// #enddocregion import-all |
36 changes: 36 additions & 0 deletions
36
public/docs/_examples/rxjs/ts/app/heroes-filtered.component.2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// #docplaster | ||
// #docregion | ||
import { _do } from 'rxjs/operator/do'; | ||
import { filter } from 'rxjs/operator/filter'; | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { HeroService } from './hero.service'; | ||
import { Hero } from './hero'; | ||
|
||
@Component({ | ||
template: ` | ||
<h2>HEROES</h2> | ||
<ul class="items"> | ||
<li *ngFor="let hero of heroes"> | ||
<span class="badge">{{ hero.id }}</span> {{ hero.name }} | ||
</li> | ||
</ul> | ||
` | ||
}) | ||
export class HeroListComponent implements OnInit { | ||
heroes: Hero[]; | ||
|
||
constructor( | ||
private service: HeroService | ||
) {} | ||
|
||
ngOnInit() { | ||
const heroes$ = this.service.getHeroes(); | ||
const loggedHeroes$ = _do.call(heroes$, heroes => { | ||
console.log(heroes.length); | ||
}); | ||
const filteredHeroes$ = filter.call(loggedHeroes$, heroes => heroes.length > 2); | ||
|
||
filteredHeroes$.subscribe(heroes => this.heroes = heroes); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
public/docs/_examples/rxjs/ts/app/heroes-filtered.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// #docplaster | ||
// #docregion | ||
// #docregion filter-import | ||
import 'rxjs/add/operator/filter'; | ||
// #enddocregion filter-import | ||
// #docregion operator | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
import { HeroService } from './hero.service'; | ||
import { Hero } from './hero'; | ||
|
||
@Component({ | ||
template: ` | ||
<h2>HEROES</h2> | ||
<ul class="items"> | ||
<li *ngFor="let hero of heroes"> | ||
<span class="badge">{{ hero.id }}</span> {{ hero.name }} | ||
</li> | ||
</ul> | ||
` | ||
}) | ||
export class HeroListComponent implements OnInit { | ||
heroes: Hero[]; | ||
|
||
constructor( | ||
private service: HeroService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.service.getHeroes() | ||
.filter(heroes => heroes.length > 2) | ||
.subscribe(heroes => this.heroes = heroes); | ||
} | ||
} | ||
// #enddocregion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters