【问题标题】:Template extensions during component extentions in Angular 5Angular 5 中组件扩展期间的模板扩展
【发布时间】:2018-11-17 22:55:09
【问题描述】:

Anular 5:为了清晰的模块结构,我想制作一些 AbstractParentComponent(具有可重用的逻辑和模板)并有可能扩展它:

    @Component({
  selector: 'app-parent',
  template: ' //reusable header element with logic

              *here we should have ability to change part of tamplate*
               <ng-container *ngTemplateOutlet="customTemplate"> </ng-container>

       //reusable footer element with logic
'
})
export class ParentComponent{
//logic impl

并且我希望能够创建扩展所有父逻辑但使用自定义模板实现自己的部分的扩展组件:

 @Component({
  selector: 'app-child',
  template: '
             //here i wanna extend parent template
             /*something like*/ <ng-template #customTemplate>
             //some template impl
</ng-template>'
})
export class ChildComponent extends ParentComponent{}

怎么可能?

【问题讨论】:

  • 尝试使用@ViewChild('changediv') changediv: TemplateRef;但没有成功
  • 你解决了吗?
  • 不幸的是,没有。我通过其他方式没有扩展,但假设可以使用 和 @ViewChild

标签: html angular typescript components angular5


【解决方案1】:

怎么样:

@Component({
selector: 'app-child',
  template: '<app-parent></app-parent>'
})
export class ChildComponent extends ParentComponent{}

【讨论】:

  • 如何将我们的子模板注入到父模板的一部分中?您的示例只是扩展父模板。
猜你喜欢
  • 2015-11-24
  • 2017-08-18
  • 2021-10-08
  • 2021-01-08
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多