This lesson is for PRO members.

Unlock this lesson NOW!
Already subscribed? sign in

Lazy Loading non-Angular Libraries with ocLazyLoad

1:06 Angular 1.x lesson by

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

Get the Code Now
click to level up comment guidelines


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

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.

Joel's Head
Why are we asking?