how to check the toggle button on/off state ionic to send to db Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of how to check the toggle button on/off state ionic to send to db without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have one text called Developer = toggle button on/off. So user can do on/off with the toggle button. But in same screen I have one button called submit. So while submitting I need to sent whether user has on/off or checked/unchecked the developer option and I need to sent that to db.

So like [ developer: yes/1/ON/ ] like this. How can i do that. If user checked the toggle button i need to keep as yes or no.

Here is my code :

<label class="item item-input " style="height: 50px;"><span class="input-labels-over"><font style="color:#696969; padding-top: 0px;">Claim</font></span>
    <ion-toggle toggle-class="toggle-calm"></ion-toggle>
</label>

My controller code :

$scope.submit = function() {}

I am stuck more than 2 hr. I am new to ionic.

If user checked means to db I need to sent yes. If user didn’t checked the toggle button I need to sent no to db.

How can I do this?

Answer

Use ng-model

<label class="item item-input " style="height: 50px;"><span class="input-labels-over"><font style="color:#696969; padding-top: 0px;">Claim</font></span<ion-toggle toggle-class="toggle-calm" ng-model="data.toggle"></ion-toggle></label>

and in the controller

$scope.data = {}
$scope.submit = function() {
 var toggleStatus = $scope.data.toggle //return true or false
 //your code
}
We are here to answer your question about how to check the toggle button on/off state ionic to send to db - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji