angular directive和 webpack html-loader

问题:

angular 的 directive支持使用template 和 templateUrl两种方式来指定模板

template的方式需要把html的内容放在js里,虽然有es6字符串可以换行, 少了编辑器对html的智能补全比较不爽

templateUrl的方式对于纯静态托管的angular项目比较友好

如果页面是后端服务器返回的话, 使用相对路径会找不到页面(这是当然的)

所以会用$templateCache 来把页面内容放到js里面(gulp 下例如ngtemplatecache 之类的工具)

还得引入额外的js 

解决:

webpack 的html-loader 把这个文件优雅的解决了.

在webpack.config.js中配置好html-loader之后, 简单使用 template: require("./template.html") 就解决了 :)

原文地址:https://www.cnblogs.com/tangkikodo/p/5998991.html