webpack with ocLazyload fails to load both controller and template files

142 Views Asked by At
var templatePath = require('../templatePath');
var controllerPath = require('../ControllerPath');

$scope.loadNgModules = function(templatePath, controllerPath) {
    var files = [];
    if (templatePath) files.push({ type: 'html', path: templatePath });
    if (controllerPath) files.push({ type: 'js', path: controllerPath});
    if (files.length) return $ocLazyLoad.load(files)
};

ocLazyLoad is not working When I use webpack for minification. Since I guess ocLazyLoad accepts only path of the template and controller but webpack is bundling both template and controller into the single minified file so it fails to load.

Webpack plugin name : uglifyjs-webpack-plugin'

Is there any way to accomplish this problem using ocLazyLoad.? Can I load a string of template and controller file other than considering path.?

1

There are 1 best solutions below

0
On

As per my understanding basically ocLazyLoad accepts only path of the script and template files

So I have resolved this issue by using $templateCache

if (angular.isString(templatePath) && templatePath.length > 0) {
angular.forEach(angular.element(templatePath), function (node) {
    if (node.nodeName === "SCRIPT" && node.type === "text/ng-template") {
        $templateCache.put(node.id, node.innerHTML);
    }
});

}

Hope this will helps to someone :-)