【发布时间】:2020-04-16 14:52:56
【问题描述】:
组件定义如下:
import {Component} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.less']
})
export class AppComponent {
}
我想在某些特定组件中加载扩展名为 htm "app.component.htm" 的文件,而不是 "app.component.html"
@Component({
selector: 'app-root',
templateUrl: './app.component.htm',
styleUrls: ['./app.component.less']
})
由于某种原因它不起作用,它说:
ERROR in ./app.component.htm 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
<p>
app component works!
</p>
「wdm」: Failed to compile.
请帮我找到一种加载 htm 文件的方法?我知道有一种方法可以使用 Webpack 进行引导,我想保留 ng-serve\cli angular.json 的当前版本!
谢谢!
【问题讨论】:
-
请提供完整的ts文件
-
因为根据angular没有像htm这样的文件所以不支持它只有在你使用angularjs时才有效
-
是什么迫使您使用 .htm 而不是 .html 文件?
-
有一个过程可以使用custom builder 生成与现有配置合并的自定义 webpack 配置,允许您为非标准化文件类型指定自定义加载器。但是,我自己从来没有真正做过,所以我不知道你需要什么的确切语法....
-
还要记住,这似乎在 8.x 中发生了变化,所以它也可能是一个死胡同......
标签: angular angular-cli