我正在使用 alpha.25 版本创建angular2应用(AddressManager)。以下是我收到错误的代码:
组件:
var AddressManager;
(function(AddressManager, Service, Utils){
'use strict';
var AddManagerInfo = Utils.at({
Component: {
selector:'address-manager',
appInjector:[Service.ManageAddress]
},
View: {
templateUrl:'address-manager.html',
directives: [angular.NgFor]
},
forClass: AddManager,
parameters: [Service.ManageAddress]
})
function AddManager (ManageAddress) {
this.appName = 'Address Manager';
this.personInfo = ManageAddress.get();
}
AddressManager.AddManager = AddManager;
})(AddressManager || (AddressManager = {}), Service || (Service = {}), Utils || (Utils = {}));
查看:(地址manager.html)
<div>Testing</div>
当我使用template:'<div>Testing</div>'
代替templateUrl:'address-manager.html'
时,它运行正常。但是templateUrl:'address-manager.html'
的错误就是抛出错误:
无法加载模板&#34; AddManager&#34;
答案 0 :(得分:2)
Angular 2希望拥有模板的绝对路径。
https://angular.io/docs/ts/latest/cookbook/component-relative-paths.html
要使用相对路径,请尝试将moduleId属性添加到组件中:
@Component({
moduleId: module.id,
selector: 'my-comp',
directives: [],
templateUrl: 'my-comp.html',
styleUrls:['my-comp.css']
})