如何从angular 4的父组件继承模板? [英] How do you inherit the template from a parent component in angular 4?

查看:204
本文介绍了如何从angular 4的父组件继承模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何从角度4的父组件继承模板?大多数材料都举例说明了覆盖父组件的方式,

How would you inherit the template from a parent component in angular 4? Most materials exemplify overriding the parent component like this:

import { Component } from '@angular/core';
import { EmployeeComponent } from './employee.component';

@Component({
  selector: 'app-employee-list',
  template: `
    <h1>{{heading}}</h1>
    <ul>
      <li *ngFor="let employee of employees">
        {{employee.firstName}} {{employee.lastName}} <br>
        {{employee.email}} <br>
        <button (click)="selectEmployee(employee)">Select</button>
      </li>
    </ul>
  `
})
export class EmployeeListComponent extends EmployeeComponent {
  heading = 'Employee List';
}

但是我想从EmployeeComponent继承模板,而不是用我自己的自定义版本覆盖它.如何做到这一点?

but I want to inherit the template from EmployeeComponent, instead of overriding it with my own custom version. How can this be achieved?

推荐答案

由于拥有子组件,因此可以将其放置在父组件的目录中,并为其提供引用父组件的URL.

Since you have a child component, you could place it in the parent's directory, and give it an URL that references the parent.

@Component({
  selector: 'app-child',
  templateUrl: '../parent.component.html',
  styleUrls: ['../parent.component.scss']
})

这篇关于如何从angular 4的父组件继承模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆