【问题标题】:How to put a component inside another component's templateUrl in Angular2+?如何在 Angular 2 中将一个组件放入另一个组件的 templateUrl 中?
【发布时间】:2018-09-01 14:21:46
【问题描述】:

如果我在我的 Angular4 父组件中使用 templateUrl,我需要包含

父模板中的子组件,如<child></child>

我怎样才能达到同样的效果?

@Component({
  selector: 'parent',
  templateUrl: './foo.parent.html'
})
export class ParentComponent {}

子组件

@Component({
  selector: 'child',
  template: `
    <h4>Child Component</h4>
  `
})
export class ChildComponent {}

【问题讨论】:

  • 请注意,您的应用组件选择器的名称应以app-... 开头(例如:app-parent

标签: angular angular2-directives


【解决方案1】:

foo.parent.html 文件中添加&lt;child&gt;&lt;/child&gt;

【讨论】:

    猜你喜欢
    • 2017-01-17
    • 2017-09-15
    • 2017-06-17
    • 1970-01-01
    • 2023-01-12
    • 2016-03-09
    • 2019-03-03
    • 2018-12-31
    • 1970-01-01
    相关资源
    最近更新 更多