The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Render an Observable with the Async Pipe

Render an Observable with the Async Pipe

2:19
Angular templates use a special Async pipe to be able to render out Observables. This lesson covers the syntax used to create an Observable in Angular and then to render it out in the template. https://github.com/johnlindquist/rxjs-in-angular2/tree/11aa4c29a4536dad0ef26b78d8f7f503e4372f74/src
Watch this lesson now
Avatar
egghead.io

Angular 2 templates use a special Async pipe to be able to render out Observables. This lesson covers the syntax used to create an Observable in Angular 2 and then to render it out in the template.

https://github.com/johnlindquist/rxjs-in-angular2/tree/11aa4c29a4536dad0ef26b78d8f7f503e4372f74/src

Avatar
Simon

How do you setup this and get it up and running? I can't figure it out from the github repo....

Avatar
jolmari

I noticed that if I use the async pipe operator more than once in my local test project template code, I get multiple calls to the API method called. Is there a way to call the async once on an Observable and then store the result for ex. separate *ngFor and *ngIf operators in the same template?

Avatar
William Grasel

What about the tree shaking strategy? It should eliminate the problem of import the whole rxjs library, and then we don't need to import each method every time, right?

Avatar
Jesse

This really needs some documentation on how to get it running. The instructions used for "getting started with angular 2" do not apply here and neither do anything I've found so far in an rxjs course. The NOTES.md file looks promising, starts with 'typings install'. Looking up typings: https://github.com/typings/typings the installation instructions npm install typings --global fails with 'typingsnpm' is not in the npm registry.
:

In reply to egghead.io
Avatar
Jesse

If anyone has gotten this project to run, please share instructions. Thank You

Avatar
themathmagician

Looks like the Plunker link og github is wrong ?

Avatar
Tom

If you are getting the 'exclude' error, hard code the typescript version to 2.0.10.

I then got a 'permission denied' error because the output path was to the root directory (e.g "/build" not __dirname + "/build")

I have submitted a pull request:

https://github.com/eggheadio-projects/angular-rxjs-time-machine/pull/1

( I had to edit this 3 times cos i kept screwing up the directory example.sorry)

In reply to Jesse
Avatar
Jesse

@Tom in your repo, only a couple of files actually clone correctly, but that seems to also be the case in the original version you forked. I ended up downloading instead of cloning the original, and then applying your changes. It worked thanks.

In reply to Tom
Avatar
Jesse

You will need to reference three different git repos to get this working and see the correct gists.

https://github.com/johnlindquist/angular-rxjs-time-machine
is the project, but
https://github.com/johnlindquist/rxjs-in-angular2
has the correct gists listed in the notes.
there are also additional user submitted fixes in a third:
https://github.com/eggheadio-projects/angular-rxjs-time-machine

time-machine repo doesnt clone correctly, perhaps the gitignore excludes everything? so download dont clone:
https://github.com/johnlindquist/angular-rxjs-time-machine
then make changes listed here:
https://github.com/eggheadio-projects/angular-rxjs-time-machine/pull/1/files
npm install
npm start

I got additional errors from awesome-typescript-loader, I think this is because I ran npm-install prior to applying the changes detailed in the fix. I went into node_modules folder of my project and deleted typescript and also awesome-typescript-loader folders, I also did npm cache clean to clear out my global npm cache which may not have been necesarry. then npm install and npm start

In reply to egghead.io
Avatar
technokon

Great lesson!
Why are we binding console to console.log?

Avatar
Suhail Taj Shaik

Can you give me some noted which node modules have you installed for up and running this Project

Avatar
kefkef5

I'm probably super late for this one, but I just throw it out here for anyone who is wondering. I was wondering the same thing.
Behind the scenes what | async does is subscribing to the observable to the observer sees values passing by. Unsubscribing is handled by Angular 2, so you won't need to worry about that.

It behaves exactly like a normal subscribe and subscribe means, start the execution. This implies that when using the async pipe on the same observable in multiple places is that you start multiple separate executions, which all of them will call the API (resulting in multiple API calls).
Whenever you want to share the execution between multiple observers, a Subject should be used.

In reply to jolmari
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?