./src/app/component/header.component.ts找不到模块:错误:无法解析'./header.component.html

问题描述 投票:0回答:2

当我安装角度时,它最初显示我默认的角度输出。但是当我创建标题组件时,显示错误就像这样..请问任何人都可以解决我的pbm ..?

我尝试了stackoverflow给出的解决方案,但它无法正常工作

import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-header',enter code here
templateUrl: `header.component.html
`,
styleUrls: []
})
export class HeaderComponent implements OnInit {
constructor() {}
ngOnInit() {}
}
angular
2个回答
0
投票

提供相对路径而不是绝对路径。

如果您的html位于同一文件夹中

templateUrl: `./header.component.html'

代替

templateUrl: `header.component.html`

0
投票

如果找不到HTML文件的路径,则可能出现错误。在代码中更改此templateUrl

templateUrl: './header.component.html',

并将您的组件添加到module.ts文件中

declarations: [HeaderComponent]
© www.soinside.com 2019 - 2024. All rights reserved.