如何在TypeScript中使用es6语法导入.html片段 [英] How to import .html fragment using es6 syntax in TypeScript

查看:131
本文介绍了如何在TypeScript中使用es6语法导入.html片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从这样的相对路径导入HTML模板:

 从./custom-select导入customSelectHtml。 HTML文本!; 

TypeScript编译器抱怨说它找不到模块。我试图创建一个环境模块定义,但它不允许模块名称中的相对路径。我正在使用SystemJS作为模块加载器。

解决方案

这是不可能的。



由于定义了什么是模块 in typescript,据我所知,在ES6 javascript(进口)。模块不能是html。常见的方法是导入一个导出包含html,css的字符串的JavaScript模块,无论如何。但是这并不是用原始HTML格式导入文件。



也许你想看看 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片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆