2

My directory structure is per module (page):

/app
    app.js
    /states
        /home
            home.module.js
            home.less
            home.controller.js
            home.html

This is my home.module.js

//import {HomeController} from "./home.controller";

function homeConfig ($stateProvider) {

    $stateProvider
        .state('home', {
            url: '/home',
            templateProvider: ($q) => {
                return $q((resolve) => {
                    require.ensure([], () => resolve(require('./home.html')), 'home');
                });
            },
            controller: 'HomeController as Home',
            resolve: {
                load: ($q, $ocLazyLoad) => {
                    return $q((resolve) => {
                        require.ensure(['./home.html'], () => {
                            let ctrl = require('./home.controller');
                            $ocLazyLoad.load(ctrl);
                            resolve(ctrl);
                        }, 'home');
                    });
                }
            }
        })
}

export default angular.module('home', [])
        .config(homeConfig)
        //.controller('HomeController', HomeController)

How do I properly use oclazyLoad and load my home controller and registering it? The point is that the module is pre-loaded but the content (html, controller, less) will be lazy loaded only when the user enters the home state. All should be bundled by webpack into one home.js file

shayy
  • 1,272
  • 2
  • 16
  • 26

0 Answers0