Getting a null array after redirection using $ location.path in angularJs

Here is my controller code where I call the getResult method: -

$scope.selectedAnswer = [];
$scope.correctAnswer = [];

$scope.result = function () {
    $(".optionlist").find("li").each(function () {
        if ($(this).attr('id') == 'true') {
            var label = $(this).parent('ul').attr('que-label');
            var value = $(this).find('input[type=checkbox]').attr('value');

            $scope.correctAnswer.push({ "label": label }, { "Option": value   });
            console.log(label);

        }
    });

$scope.getResult = function () {

$location.path("/reviewans");
}

      

Here is my pagepage block: -

<div class="list-group list_top" data-toggle="items">

<ul class="left1 optionlist" data-value="{{$index+1}}" que-label="{{Questions.QuestionLabel}}">

<li class="list group-items alert alert-danger alert_template" style="display:none">
<a class="close" data-dismiss="alert" aria-label="close">&times;</a><span class="spantext"></span>
</li>

<li ng-repeat="Options in answerlist" ng-if="Questions.QuestionID == Options.QuestionID" id="{{Options.IsCorrectOption}}" ng-show="Options.QuestionID == Questions.QuestionID" ng-click="!IsAutoslide||AutoSlide(Options.QuestionID)">

<a href="#" class="list-group-item"><input type="checkbox" value="{{Options.QuestionOptionID}}" style="display:none">{{Options.OptionText}}</a>
</li>


</ul>

</div>
<div><a class="btn btn-default finish" style="display:none" ng-click="getResult()">Finish</a></div>

      

And here is my block of review pages: -

<div class="tab-pane fade" id="messages" ng-init="result()">
                        <div class="all_ques_back col-md-12" ng-repeat="ans in correctAnswer">
                            <div class="col-xs-1 col-md-1"><i class="fa fa-times-circle fa-2x col_padd wrong_ans_font"></i></div>
                            <div class="col-xs-9 col-md-10 col_padd"><div class="all_ques" ng-repeat="(key, val) in ans">hello your ans {{val}}</div></div>
                            <div class="col-xs-1 col-md-1 col_padd"><i class="fa fa-angle-right right_arrow"></i></div>
                        </div><!-----end------>

                    </div>

      

the problem is i get null result in the correct answer after redirecting with location.path

0


source to share


1 answer


I don't see you filling out '$ scope.correctAnswer' anywhere? Maybe you want to use '$ scope.selectedAnswer' ?



0


source







All Articles