简体   繁体   English

为什么在webpack中需要html文件时会得到位置字符串?

[英]Why I get a location string when requiring a html file in webpack?

var uib = $uibModal.open(
  {
    template: require('./create/create.html'),
  }
)

I want get content in create.html and show it in modal,but it shows ./create/create.html ,the string of the location in modal. 我想要在create.html中获取内容并以模式显示它,但它显示./create/create.html (模式中位置的字符串)。

I've add html loader in webpack.config.js: 我在webpack.config.js中添加了html loader:

    {
      test: /\.html$/,
      loader: 'raw-loader',
    },

You should use templateUrl 您应该使用templateUrl

var uib = $uibModal.open({

  templateUrl: require('./create/create.html'),

});

when you want to declare html code in your js that time you can use template 当您想在js中声明html代码时,可以使用template
but if you want to call html page like create.html that time you have to call it by templateUrl 但是如果您想在create.html调用诸如create.html类的html页面,则必须通过templateUrl进行调用

also you can write code in template like :- 您也可以在template编写代码,例如:

var uib = $uibModal.open({

  template: '<html><h3> Hie i am in js </h3></html>'

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 webpack 在需要输出时返回一个空对象? - Why webpack returns an empty object when requiring its output? 为什么在使用Webpack时我们需要React和ReactDOM作为模块? 产生输出需要很长时间 - Why are we requiring React and ReactDOM as modules when working with Webpack? It takes long to produce output 为什么当我尝试将字符串添加到我的数组位置时不起作用 - Why is not working when i try to add a to a string to my array location 使用Webpack将模板字符串写入.html文件 - Write template string to .html file with Webpack 当我想使用 JavaScript 从 HTML 中获取字符串时,为什么会得到 Null - Why am I getting Null when I want to get a String from an HTML with JavaScript 为什么节点找不到模块? (即使我不需要它) - Why can node not find a module? (Even when I'm not requiring it) 需要文件时出了点问题 - Something wrong when requiring file 为什么我保存更改时“webpack serve”命令不刷新 html 页面? - Why the 'webpack serve' command doesn't refresh the html page when I save the changes? 使用来自 HTML 文件的 WebPack 构建包时如何获得 WebStorm 代码完成? - How to get WebStorm code completion when using a WebPack built bundle from HTML file? 为什么会出现此Webpack加载器错误? - Why do i get this Webpack loader Error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM