Join egghead, unlock knowledge.

Want more egghead? It's 45% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 45% Off

Already subscribed? Sign In

Save 45% for a limited time.

Get access to all courses and lessons on egghead today.

Autoplay

    Render an Observable Date with the Async and Date Pipes

    John LindquistJohn Lindquist

    Instead of simply pushing numbers on a timer into the template, now we'll move on to pushing actual Dates. We'll still use the Async pipe, but we'll also add on the Date pipe with some formatting to display the Date just the way we want it.

    angularAngular
    2 - 6
    ngrx-store@ngrx/store
    rxjsRxJS
    5 - 6
    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    00:00 To turn this clock into a working clock instead of just pumping out zero through infinity, what we need to do is push out a date. We're going to map, which takes a function. Each time this ticks we're going to return a new date. Don't forget, every time you use a method you have to import it here. I'll go ahead and import map. Now once I hit Save and I refresh over here, you can see that now we'll get some dates printed out.

    00:31 We actually have control over this date if we use the date pipe, which I'll go ahead and use. Date and then that takes a format string, which I'm just going to go ahead and copy and paste in. Looks like this. I'll hit Save and Refresh. You can see we get the full Wednesday and then a bit nicer format for our time.

    00:56 All of these formats are the standard date formats you see in other languages. You can find them in the Angular docs if you want to format this however you want.

    Discuss

    Discuss