How to use JavaScript returned by AngularJS minified partials

661 Views Asked by At

I am minifying my angularjs application and as part of which I used gulp-ng-html2js to minify the partials, that seems really good because it convert all the html partials into a single javascript file, but then I'm not sure how to use/invoke this javascript file from my application to access the partial, I tried to find some kind of documentation but and nothing is available on the web; may be my search terms or keys aren't accurate enough. Please find the code below. Please do help me figure out this, frankly speaking I believe I'm missing something basic out there.

//gulp script for minification of html partials
...
....
....
gulp.task('htmlmin', function () {
    var opts = {
        empty: true,
        spare: true,
        quotes: true
    };

    gulp.src(paths.partialsSrc)
        .pipe(minifyhtml(opts))
        .pipe(ngHtml2Js({
            moduleName: "erentrollinternet",
            prefix: "/partials/"
        }))
        .pipe(concat("partials.min.js"))
        .pipe(uglify())
        .pipe(gulp.dest(paths.partialsDest));
});
....
....


// this is the resulting file
!function(t){
    try
    {
        t=angular.module("modulename")
    }
    catch(e)
    {
        t=angular.module("modulename",[])
    }
    t.run(["$templateCache",
    function(t)
    {
        t.put("/partials/components/building/Buildings.html",
        '<div class="main"><div class="controls">
            .....
            .....
            .....
          </div></div></div>')}])
    }(),
    function(t)
    {
        try{t=angular.module("erentrollinternet")
    }catch(e)
    {
        t=angular.module("erentrollinternet",[])
    }

}])}();
1

There are 1 best solutions below

4
On BEST ANSWER

the keys used to store templates in $templateCache are the same as the url you would use if the files were still on server.

angular will look in $templateCache any time you set a templateUrl in routing, directive , ng-include etc

If that url is found in cache it will pull the html out of the cache object internally. If not found it will make a server request for the template

In short, you shouldn't have to do anything different in your module code to use them the way they are minified now.