I'm trying to pass a single variable from one component to another. It is an array and is declared as follows.
@Component({
selector: 'component1',
templateUrl: './component1.component.html',
styleUrls: ['./component1.css'],
})
export class Component1 implements OnInit{
......
columnVars = Object.keys(this.settings.columns);
......
}
So I set up my second component to extend my first and reference the variable like so and it works just as expected.
<table>
<thead>
<tr>
<th>Column</th>
<th>Description</th>
</tr>
</thead>
<tbody *ngFor="let col of columnVars">
<tr>
<td>{{settings.columns[col]['title']}}</td>
<td>{{settings.columns[col]['description']}}</td>
</tr>
</tbody>
</table>
The second component looks like this and this is where the problem comes in.
@Component({
selector: 'component2',
templateUrl: './component2.html',
styleUrls: ['./component2.css']
})
export class Component2 extends Component1 implements OnInit {
buttonObjList = {
headendsButton: {
title: 'Back to headends',
route: '/headends',
}
};
}
I get the error
ERROR in /home/grady/honeybadger-mat/src/app/column-info/column-info.component.ts (9,14): Class 'ColumnInfoComponent' incorrectly extends base class 'IngestViewComponent'.
Types of property 'buttonObjList' are incompatible.
Type '{ headendsButton: { title: string; route: string; }; }' is not assignable to type '{ columnInfo: { title: string; route: string; }; }'.
Property 'columnInfo' is missing in type '{ headendsButton: { title: string; route: string; }; }'.
Which makes sense. So now my question is is there a way to pass a variable to another component without inheritance or a way to override specific inherited variables like buttonObjList? Thank you in advance.
Edit: To clarify I do not need to display this second component in my first component. So it seems the @input directive won't benefit me in this case. Correct me if I'm wrong.