Join egghead, unlock knowledge.

Want more egghead?

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

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Lazy Loading non-Angular Libraries with ocLazyLoad

    John LindquistJohn Lindquist

    ocLazyLoad will also load non-Angular libraries in the lazy way.

    javascriptJavaScript
    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 Now, I want to add the date to the store template that I've loaded in. I'll say Store.Date, and then I'll just pay some Moment code, Moment's a great library for formatting and showing dates. Then, I'll go into my HTML here.

    00:14 We'll make it an H2 and do Store.Date. Then you suddenly realize that, "Wait a second. I haven't loaded in this Moment library yet. How am I going to do that? This is in a loaded-in module. Do I have to go back and add it all the way into my index HTML?"

    00:31 The answer is "No. You can simply load in any library by just passing it in." I'll use a live template here for a moment and just load in Moment. You can see, once I refresh, hit Click Me, that it formats and displays the date.

    00:46 If you check out the network tab, you can see that Moment, once I refresh, is not loaded up front in any of these, but once I hit Click Me, that Moment is the last thing loaded. It loads in the store and the cart in Moment and everything. It satisfies all those dependencies for you.

    Discuss

    Discuss