Become a member
to unlock all features

Level Up!

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


    Simple Lazy Loaded Angular Module Syntax with ocLazyLoad


    ocLazyLoad offers several ways to lazy load your AngularJS modules. This lesson looks at the syntax for lazy loading dependencies declared in the module definition.



    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




    So in this scenario, when we click on this button, we go to the store state and the store state loads up these store files and the store module. I'll click that and everything will load in, the store template, and the store but what if I need the cart service and the list service off the cart module inside of my store and that's in a completely different file.

    You can actually load that as another file here in the list of files but an awesome convenience here is that I can put an object in the list of dependencies where I can say, name is cart and then files is the list of files, so just cart/cart.js here. Then, I can inject my list service and show my list.items.

    I'll save this. I'll come over here and refresh. I'll say click me and now it's showing my list of items from cart module. Again, this is simply an object that I'm passing into the list of dependencies where you typically load modules and this is a custom syntax for this OC lazy load library. You say name of the module. Again, the files, just like you would if you were loading in from a resolve statement.

    Then, you can use the regular injection-like list to get the list service off of that cart module. Nothing fancy going on here. The only fancy thing is this great little short and sweet syntax of loading in a file that's not in my current file and then using a module and the services off of it.