WebPACK中:使用需要NG-包括: [英] Webpack: using require for ng-include

查看:628
本文介绍了WebPACK中:使用需要NG-包括:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的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.

这篇关于WebPACK中:使用需要NG-包括:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆