WebPACK中:使用需要NG-包括:WebPACK、NG

2023-09-14 23:09:46 作者:言不尽

我是新来的WebPack而现在我在我的角度项目之一使用它的第一次。

I'm new to webpack and right now I'm using it for the first time in one of my angular projects.

我想使用的功能,需要在我的HTML文件,以便需要一个模板NG-包括像这样:

I want to use the require function in my html file in order to require the template for an ng-include like so:

<div ng-include="require(./my-template.html)"></div>

我知道有像NG-cache和ngtemplate装载机,但他们没有工作,我需要的方式。有了他们,我得先需要在JS模板,比我的HTML文件中使用的模板名称。

I know there are loaders like ng-cache and ngtemplate, but they do not work the way I need it. With them, I have to require the template in an js first and than use the template name in my html file.

如何做到这一点?

推荐答案

您可以使用的WebPack要求的-loader 在NPM。

在您的应用程序的js或模块JS添加评论:

In your app js or module js add comment:

//@require "./**/*.html" 

而在你的模板,您可以用

And in your template you can use

<div ng-include="./my-template.html"></div>

Ngtemplate将正常工作。伍缓存我不考。

Ngtemplate will works fine. Ng-cache I don't test.