问题描述
如何从这样的相对路径导入HTML模板:
从./custom-select导入customSelectHtml。 HTML文本!;
TypeScript编译器抱怨说它找不到模块。我试图创建一个环境模块定义,但它不允许模块名称中的相对路径。我正在使用SystemJS作为模块加载器。
这是不可能的。
由于定义了什么是 in typescript,据我所知,在ES6 javascript()。模块不能是html。常见的方法是导入一个导出包含html,css的字符串的JavaScript模块,无论如何。但是这并不是用原始HTML格式导入文件。
也许你想看看也是,但这是完全不一样的。
How to import an HTML template from a relative path like this:
import customSelectHtml from "./custom-select.html!text";
TypeScript compiler complains that it cannot find module. I was trying to create an ambient module definition, but it doesn't allow relative paths in module names. I am using SystemJS as a module loader.
It is impossible.
Due to the definition of what is module in typescript, and as far as I know in ES6 javascript (import). Module cannot be html. The common approach is to import a javascript module that exports a string containing html, css, whatever. But that is not importing of the file with raw html.
Maybe you want to have a look at html imports also, but that is completely different thing.
这篇关于如何在TypeScript中使用es6语法导入.html片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!