【问题标题】:angular2 nested component templateUrl will not be find找不到angular2嵌套组件templateUrl
【发布时间】:2017-03-09 18:25:27
【问题描述】:

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

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

这是我的代码:

子组件:

@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{}

【问题讨论】:

    标签: angular nested components


    【解决方案1】:

    试试这个代码

    @Component({
        moduleId: module.id
        selector: 'edit-task',
        templateUrl: 'file.component.html'
    
    })
    export class FileFormat{}
    

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

    或者在 telplateUrl 中从根目录给出完整路径

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      • 2017-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多