简体   繁体   English

如何在typescript中导入template.html

[英]how can import template.html in typescript

i want to include template in my typescript how can do that?? 我想在我的打字稿中包含模板怎么做?

var template = import './template.html'

i use web pack and bundle all file into one javascript file. 我使用Web包并将所有文件捆绑到一个javascript文件中。

i use angularjs (v1) and want to build component base project using typescript gulp and webpack and now i use this code. 我使用angularjs(v1)并希望使用typescript gulp和webpack构建组件基础项目,现在我使用此代码。

declare var require:any;
import  './cart.template.html';
import {cartController} from './cart.controller'

export var cartComponent = {
    template: require('./cart.template.html'),
    controller:cartController
}

is there any better solution for doing this??? 这有什么更好的解决方案???

first, declare an HTML module like this: 首先,声明一个这样的HTML模块:

declare module "*.html" {
const content: string;
export default content;
}

then, use it: 然后,使用它:

import * as template from "template.html";

 @Component({
 selector: 'home',
 directives: [RouterLink],
 template: template
 })

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

相关问题 在template.html中使用javascript中的字符串 - using a string in javascript from a template.html 从template.html调用控制器中的函数 - call function in controller from template.html 如果条件要使用Ionic和angular处理template.html - If condition to handle template.html with Ionic and angular 如何在Visual Studio“TypeScript HTML App”模板中导入TypeScript类? - How to import a TypeScript class in visual studio “TypeScript HTML App” template? 如何在 Django 中单击 template.html 中的按钮时调用 views.py 中的函数 - How to call a function in views.py on clicking a button in template.html in django 从views.py获取Django Python数据到template.html中的javascript对象 - Getting Django Python data from views.py to javascript object in template.html 如何在我的模板(Angular2 / TypeScript)中将HTML字符串转换为HTML? - How can I convert strings of HTML into HTML in my template (Angular2/TypeScript)? Angular 9 如何使用 TypeScript 将 HTML 文件作为字符串导入? - Angular 9 How to import HTML file as a string with TypeScript? 如何为TypeScript文件创建模板? - How can I create a template for a TypeScript file? 我可以将 x-template 脚本导入 HTML 文件吗? - Can I import x-template script into HTML file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM