This is an AngularJS problem; I have a simple form:
<input type="text" class="form-control" id="qus" placeholder="Enter Question" ng-model="qus">
<input type="text" class="form-control" id="op1" placeholder="Option 1" ng-model="op1">
<label><input type="checkbox" ng-model="correct1">Correct</label>
<button class="form-control btn btn-primary" ng-click = "save()">Save</button>
<pre ng-bind="dataShow"></pre>
Script:
var app = angular.module('qApp', []);
app.controller('qCtrl', function($scope) {
var set = [];
var op1 = [];
$scope.save = function (){
if($scope.correct1!==true){$scope.correct1=false;}
op1.push($scope.op1, $scope.correct1);
var qus = [$scope.qus, op1];
set.push(qus);
$scope.dataShow = JSON.stringify(set);
};
});
Outputs:
After using JSON.stringify for the first entry the output looks like this:
[
["q1",["o1",false]]
]
and the output for the second entry is:
[
["q1", ["o1",false,"o2",true]],
["q2", ["o1",false,"o2",true]]
]
But I wanted something like this:
[
["q1", ["o1",false,]],
["q2", ["o2",true]]
]
How to do that? true/false is the value of a check box.