简体   繁体   中英

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.

i use angularjs (v1) and want to build component base project using typescript gulp and webpack and now i use this code.

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:

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
 })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM