I have a Shared Component Input Radio where I pass multipes @Input(). My problem is that the [value]="value" does not feed back the information in my parent. No value in HTML
shared-button-choice.html
<input id="{{value}}" [type]="inputType" [value]="value" [name]="name" [formControl]="formControl">
Call Shared Component :
<shared-button-choice
inputType="radio"
name="typeLogement"
label="Maison"
value="maison"
formControlName="typeLogement"
picture="assets/images/g1.png"
>
</shared-button-choice>
shared-button-choice.ts
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import {
ControlContainer,
FormControl,
FormControlDirective,
NG_VALUE_ACCESSOR,
} from '@angular/forms';
@Component({
selector: 'shared-button-choice',
templateUrl: './button-choice.component.html',
styleUrls: ['./button-choice.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: ButtonChoiceComponent,
multi: true,
},
],
})
export class ButtonChoiceComponent implements OnInit {
@Input() label: string;
@Input() value: string;
@Input() name: string;
@Input() picture: string;
@Input() inputType: string;
@Input() formControlName: string;
@ViewChild(FormControlDirective, { static: true })
formControlDirective: FormControlDirective;
formControl: FormControl;
constructor(private controlContainer: ControlContainer) {}
ngOnInit(): void {
this.formControl = this.controlContainer.control.get(
this.formControlName,
) as FormControl;
console.log('ctrl', this.formControl);
}
registerOnTouched(fn: () => void): void {
this.formControlDirective.valueAccessor.registerOnTouched(fn);
}
registerOnChange(fn: () => void): void {
this.formControlDirective.valueAccessor.registerOnChange(fn);
}
writeValue(obj: string): void {
this.formControlDirective.valueAccessor.writeValue(obj);
}
}