创建我的第一个Angular 2应用程序我尝试使用templateUrl在html文件中设置我的模板。
目前,我将component.ts和view.html放在src /文件夹下的同一个文件夹中,我使用它:
@Component({
selector: 'relative-path',
templateUrl: 'view.html'
})
运行应用后,控制台会说:
zone.js:1274GET http://localhost:3000/personalData.html 404(未找到)
知道我做错了什么吗?
答案 0 :(得分:2)
设置moduleId
,如下所示:
@Component({
moduleId: module.id,
selector: 'relative-path',
templateUrl: 'some.component.html',
styleUrls: ['some.component.css']
})
有关文档,请参阅Component-relative Paths
答案 1 :(得分:1)
您确定要使用与html文件名相同的名称吗?
例如:文件名是“myView.html”
在templateUrl:'myView.html'
答案 2 :(得分:1)
您需要添加./
,它才有用。
@Component({
selector: 'relative-path',
templateUrl: './view.html'
})
使用绝对路径更加容易,如果您按照官方样式指南,在尝试查找组件的模板时,您很可能永远不需要相对路径。
答案 3 :(得分:1)
解决!
public String getLocationByNameAndPrice(String name)