我正在尝试使用import
html模板,以便Webpack能够识别它们并在构建时包括它们。(webpack -d
)
根据这个GitHub问题,我应该这样做
declare module '*.html' {
const _: string;
export default _;
}
然后import template from './myTemplate.html';
应该工作。
但这并不能解决问题。
import template from './myTemplate.html';
console.log(template); // undefined
但是,这“有效”
import * as template from './myTemplate.html';
console.log(template); // <p>Hello world!</p>
很奇怪。
但是现在这不起作用
$routeProvider.when("/test", {
template: template, // ERROR! template is typeof(*.html) expected string
controller: MyController,
controllerAs: "$ctrl"
});
但是,如果我将* .html模块更改为
declare module '*.html' {
const _: string;
export = _; // changed this
}
我现在可以做
import * as template from './myTemplate.html';
$routeProvider.when("/test", {
template: template, // Great success!
controller: MyController,
controllerAs: "$ctrl"
});
它有效,但是为什么不起作用import template from './myTemplate.html';
?我在做错什么,因为GitHub问题中的其他人似乎使它像这样工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句