我正在使用 Angular 9.1.3 和 Typescript 3.8.3。
我想将 html 文件作为原始字符串导入。
对于这种情况:
import * as template from "./projects.page.html";
console.log("Template: ", template);
Run Code Online (Sandbox Code Playgroud)
我收到错误:
ERROR in src/app/features/projects/projects.page.ts:41:27 - error TS2307: Cannot find module './projects.page.html'.
41 import * as template from "./projects.page.html";
Run Code Online (Sandbox Code Playgroud)
如果我添加html.d.ts文件:
declare module "*.html" {
const content: string;
export default content;
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
ERROR in ./src/app/features/projects/projects.page.html 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process …Run Code Online (Sandbox Code Playgroud)