【问题标题】:Why I get a location string when requiring a html file in webpack?为什么在 webpack 中需要一个 html 文件时我得到一个位置字符串?
【发布时间】:2016-08-18 09:15:08
【问题描述】:
var uib = $uibModal.open(
  {
    template: require('./create/create.html'),
  }
)

我想在 create.html 中获取内容并以模态显示,但它显示./create/create.html,模态中的位置字符串。

我在 webpack.config.js 中添加了 html 加载器:

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

【问题讨论】:

    标签: javascript angularjs node.js webpack frontend


    【解决方案1】:

    你应该使用templateUrl

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

    当您想在js 中声明html 代码时,您可以使用template
    但是如果你想调用像create.html这样的html页面,你必须通过templateUrl调用它

    您也可以在template 中编写代码,例如:-

    var uib = $uibModal.open({
    
      template: '<html><h3> Hie i am in js </h3></html>'
    
    });
    

    【讨论】:

    • 我看到另一个项目以我的方式需要一个 html 文件并且它可以工作,我不知道为什么
    • 有没有办法在js中获取html中的原始内容?
    • 看看你是否使用template然后你可以像&lt;html&gt; &lt;head&gt;...... &lt;body&gt;..一样在其中声明html代码,所有你可以在模板中声明但是当你使用给任何html的路径时,然后使用templateUrl所以它将允许访问该特定页面
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 2022-01-26
    • 2020-12-06
    • 1970-01-01
    相关资源
    最近更新 更多