Here is the link of POC on stackblitz.
In above POC I have app
component as a root component, app-expansion-panel
component as a reusable generic component and custom-expansion-panel
directive as a custom directive. In app.component.html
I used app-expansion-panel
component and in that component I passed mat-slide-toggle using custom-expansion-panel
directive. But somehow it is not working.
mat-slide-toggle should work properly.
You are binding a method, and declaring the array inside that same method, so this is what is happening.
These are few easy solutions to the problem
constructor(){
this.featureExpansionPanelData = [
{
label: 'Name',
value: 'sample name',
injected: false,
},
{
label: 'Enabled',
value: '',
injected: true,
},
];
}
getFeaturesExpansionPanelData() {
return this.featureExpansionPanelData;
}
constructor(){
this.featureExpansionPanelData = [
{
label: 'Name',
value: 'sample name',
injected: false,
},
{
label: 'Enabled',
value: '',
injected: true,
},
];
}
<app-expansion-panel
[panelDataInput]="featureExpansionPanelData"
panelTitle="{{ name }}"
>
panelData: KeyValueAttributes[] = [];
@Input()
set panelDataInput(value) {
if (this.panelData.length === 0) {
this.panelData = value;
}
}
<app-expansion-panel
[panelDataInput]="getFeaturesExpansionPanelData()"
panelTitle="{{ name }}"
>