首页 > 解决方案 > 角度扩展一个类来改变输入

问题描述

所以我正在构建一个组织结构图,扩展一个第三方库:

https://github.com/dabeng/ng-orgchart

我正在尝试更改图表中显示的内容。以下是一些示例数据:

  datasource = {
    'id': '1',
    'name': 'Lao Lao',
    'title': 'general manager',
    'routing' : 'abc'
    'children': [
      { 'id': '2', 'name': 'Bo Miao', 'title': 'department manager', 'routing': 'abd' },
      { 'id': '3', 'name': 'Su Miao', 'title': 'department manager', 'routing': 'bcd'}
     ]
   }

我正在扩展这个类:

https://github.com/dabeng/ng-orgchart/blob/master/projects/ng-orgchart/src/lib/components/orgchart/chart-container/chart-container.component.ts

并尝试像这样更改其中一个输入:

export class OrgChartComponent extends OrgChartContainer {

  @Input() nodeContent = ['title', 'routing'];

但我收到以下错误:

Property 'nodeContent' in type 'OrgChartComponent' is not assignable to the same property in base type 'ChartContainerComponent'.
  Type 'string[]' is not assignable to type 'string'.

我怎样才能做到这一点,以便我可以将数据中的多个内容放入 nodeContent 中?我不只是想要标题,我还希望路由号码也显示在那里。

标签: angularinheritance

解决方案


nodeContent 属性是字符串,而不是 ChartContainerComponent 中的字符串数组(请参阅您发布的github 链接)。在 OrgChartComponent 中分配单个字符串值


推荐阅读