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


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

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

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

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

你应该使用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>'
});

最新更新