I'm using Angular 4 Reactive Forms, with "Ionic(3) native" UI components, and techniques from various "nested reactive forms" blogs/tutorials to create a dynamic, multi-section data entry app.
I wanted a reusable segmented control component that takes in a title & an array of options (based on a dropdown selection) so I don't have to create multiple nearly identical sub-form components.
It all works great the 1st time, but appeared to break after a subsequent selection if the ion-segment
changes its number of buttons or their label values (if 2 selections happen to have identical options, the segment buttons all still work fine).
Example: The initial set of 3 options had "adult & "unknown" ...
After changing the dropdown & the passed-in array of segment options, the common choices can still be selected, but I cannot set "calf" or "yearling" as Active (although in the component code & formGroup model it does get set). If I first select "goat", which only has 1 "unknown" option, that's the only one I can select.
"Calf" only turns light/disabled instead of "Active". This is what I need to fix.
It properly updates to show the correct number of buttons with the correct labels, and it properly updates the formGroup model even when it appears broken, but the "Active" state only works for the 1st selection. I've tried using (click)
and (ionSelect
) to call the method on the button, but no difference.
Basically everything seems to work except for the Ionic styling & CSS classes on subsequent changes to the @Input
array of button options.
MY QUESTION:
Where/how can I tell the Ionic <ion-segment>
to only use the latest values & # of segments?? The examples in tutorials or Ionic docs use static lists and template-driven forms with [(ngModel)]
data-binding, which I can't use w/a reactive form. Is this only possible with template-driven forms??