1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Lazy Loading non-Angular Libraries with ocLazyLoad

    javascriptJavaScript

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

    Code

    Code

    Become a Member to view code

    You must be a Pro 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
    orLog In
    Discuss

    Discuss

    Transcript

    Transcript

    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.

    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?"

    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.

    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.