0

I have a modular app who have multiple vendor plugins and I need to load only necessary in every view.

This is my routes:

(function() {
    'use strict';

    angular.module('app.empresas').config(config);

    function config($stateProvider, $ocLazyLoadProvider) {
        $stateProvider
            .state('app.empresas', {
                url: '/empresas?Filter',
                views: {
                    'main@': {
                        template: require('./empresas/empresas.html'),
                        controller: "AppController as App"
                    }
                },
                Params: {
                    title: 'Empresas',
                    bodyClass: '',
                    requiredLogin: true
                }
            })
            .state('app.empresas.view', {
                url: '/empresas/:ItemId',
                views: {
                    'main@': {
                        template: require('./empresas.view/empresas.view.html'),
                        controller: "AppController as App"
                    }
                },
                Params: {
                    title: 'Empresa',
                    bodyClass: '',
                    requiredLogin: true
                }
            })
    }
})();

I know how to include oclazyload resources without webpack, but now I need to include specific resources for every view. ¿How can do this?

4

1 回答 1

0

我用这个片段解决了它:

这是一个州的样本

.state('app.empresas.view', {
    url: '/empresas/:ItemId',
    views: {
        'main@': {
            templateUrl: '/app/main/apps/empresas/empresas.view/empresas.view.html',
            controller: "AppController as App"
        }
    },
    Params: {
        title: 'Empresa',
        bodyClass: '',
        requiredLogin: true
    },
    resolve: ['$q', '$ocLazyLoad', function ($q, $ocLazyLoad) {
        var deferred = $q.defer();

        var mod = importAll(require.context('./empresas.view/', true, /\.*$/));
        $ocLazyLoad.load({
            name: 'app.empresas.view'
        });
        deferred.resolve(mod);

        return deferred.promise;
    }]
})

我将此功能与 require 一起使用,以使用 oclazyload 加载整个文件夹,并使用 webpack 在捆绑的单独文件中进行编译:

function importAll (r) {r.keys().forEach(r);}

我可以在一个视图中加载css,html,js文件,而无需一个一个的文件

于 2017-04-30T14:21:47.503 回答