将无法找到angular2嵌套组件templateUrl

时间:2016-10-27 07:10:18

标签: angular nested components

我想使用嵌套组件。 这个精美的教程显示,我怎么能这样做:

https://www.themarketingtechnologist.co/building-nested-components-in-angular-2/

我的问题是,找不到嵌套组件的模板: 我试过了

template: '<h2>HALLO</h2>'

但我想使用extern文件:task.component.html,如下所示:

 template: 'file.component.html'

输出就是,那就是

  

task.component.html

将显示

当我尝试时:

templateUrl: 'file.component.html'

我收到错误:

  

未捕获(承诺):无法加载task.component.html

这是我的代码:

ChildComponent:

@Component({

    selector: 'edit-task',
    templateUrl: 'file.component.html'

})
export class FileFormat{}

为父级:

@Component({
    moduleId: module.id,
    selector: 'my-app',
    templateUrl: 'app.template.html',
    directives: [FileFormat]
})
export class FileFormat{}

1 个答案:

答案 0 :(得分:1)

试试这段代码

@Component({
    moduleId: module.id
    selector: 'edit-task',
    templateUrl: 'file.component.html'

})
export class FileFormat{}

实际上问题是角度没有正确获取路径,使用它相对路径使用moduleID

或者从根

给出telplateUrl中的完整路径
相关问题