angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.13k stars 1.24k forks source link

ng-include couldn't get template on PRODUCTION mode #2507

Open ZarinaChe opened 7 years ago

ZarinaChe commented 7 years ago
Item Version
generator-angular-fullstack 4.1.3
Node 6.9.4
npm 4.1.1
Operating System Ubuntu 16.04 LTS
Item Answer
Transpiler Babel
Markup HTML
CSS SCSS
Router ui-router
Client Tests Jasmine
DB MongoDBAuth

I'm experiencing problems with ng-include directive in production. While in development it works because required template exists. And on production (after building project and running from dist) I get 404 when angular tries to load this template.

Is this well known issue?

ZarinaChe commented 7 years ago

Can anyone suggest something?

Awk34 commented 7 years ago

You could do something like this to put the template into the Angular template cache directly:

angular
    .module('template',[])
    .run(['$templateCache', function($templateCache) {
        var url = 'views/common/navigation.html';
        $templateCache.put(url, require(url));
    }]);

source: https://stackoverflow.com/questions/33436729/webpack-using-require-for-ng-include

ZarinaChe commented 7 years ago

I tried to replace raw loader with another loader but I coudn't adopt to my project.

$templateCache is currently best solution for me.

Thanks!