In my angular 6 application i am in the need to use three state toggle switch which has the order,
---ON---NA---OFF---
For which i have used the following Html,
<div class="switch-toggle switch-3 switch-candy">
<input id="on" name="state-d" type="radio" checked="">
<label for="on" onclick="">ON</label>
<input id="na" name="state-d" type="radio" checked="checked">
<label for="na" onclick="">N/A</label>
<input id="off" name="state-d" type="radio">
<label for="off" onclick="">OFF</label>
<a></a>
</div>
Couldn't share the css file because it has lot of codes..
Working Example: https://stackblitz.com/edit/angular-6-template-driven-form-validation-z2rsig
In which you could able to see two times made switch boxes in which the first one is entirely hard coded radio buttons..
But in second i am trying to make it dynamic but i am unable to get the same UI and value of the selected switch..
The thing i am in the need is, Need to make three state toggle switch which will have values as On --- NA --- Off
. IF user switch to Off
then the value of state-d
needs to be Off
and if its On
then the value of state-d
needs to be On
and likewise for NA
. In default the NA
needs to be selected (checked)..
I am need of result as like first one in the link https://stackblitz.com/edit/angular-6-template-driven-form-validation-z2rsig
But the radio buttons needs to be dynamic as like i am tried in second one in the same link.. (It doesn't works).
Html:
<div *ngFor="let option of options" class="switch-toggle switch-3 switch-candy">
<div class="radio">
<input type="radio"
name="state-d"
id="{{option.id}}"
[(ngModel)]="value"
[value]="option.value"
/>
<label for="{{option.id}}">{{option.id}}
</label>
</div>
</div>
Ts:
public options = [
{value: "on", id:"On"},
{value: "na", id:"NA"},
{value: "off", id:"Off"},
]
Also i need to get the value of the current switch.
Kindly help me to achieve the expected result via dynamic generation of radio buttons and make the NA
default value upon switching the buttons make change the values accordingly..
Result is expected without using any third-party libraries (even angular material not allowed) or jquery.. It is good if there is change in the UI but expected result is in pure angular, typescript/javascript based.
500 lines
of css (app.component.css) code is needed to make this three state toggle.. Is there any easy way of achieving it?? UI can also be changed which i have mentioned in question.. – Maniraj Murugan