Lar*_*sen 1 module wildcard typescript2.2 angular
我在 angular 2 应用程序中导入 html 模板时遇到问题。
在 globals.d.ts
declare module "*.html" {
const content: string;
export default content;
}
Run Code Online (Sandbox Code Playgroud)
在 app.component.ts
import { Component } from '@angular/core';
import './app.component.css';
import * as template from './app.component.html';
@Component({
selector: 'app',
template: <string>template
})
export class AppComponent {
constructor() {
console.log('I am App');
}
}
Run Code Online (Sandbox Code Playgroud)
该应用程序可以工作并且模板已加载,但我收到此错误 TS2352:类型 'typeof "*.html"' 无法转换为类型 'string'。有人有解决方法吗?
我想这样做。
import template from './app.component.html';
@Component({
template: template
})
...
Run Code Online (Sandbox Code Playgroud)
但转译后的代码最终是这样的。
var app_component_html_1 = __webpack_require__(653);
...
template: app_component_html_1.default
Run Code Online (Sandbox Code Playgroud)
app_component_html_1 是我需要的字符串。他们为什么要添加 .default?
| 归档时间: |
|
| 查看次数: |
825 次 |
| 最近记录: |