0

Here is my controller code where I'm calling 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 optionpage 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 reviewans page block :-

<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>

problem is i'm getting null result in correctAnswer after redirection using location.path

Nimesh khatri
  • 763
  • 12
  • 29
  • Could you please create plunker with above code? – User2 Jul 17 '15 at 06:46
  • ok dear i have not that much of time to create demo because it is very large project so it takes time to describe problem, my problem is similar to this :-http://stackoverflow.com/questions/13882077/angularjs-passing-scope-between-routes check this link's question ... Thanks in advance .. – Nimesh khatri Jul 17 '15 at 07:00
  • i want to do something like : 1. Set $scope.val = 2. Click a link and be routed to a new template (probably with the same controller). 3. $scope.val should still be the same value as it was on the last page. – Nimesh khatri Jul 17 '15 at 07:01

1 Answers1

0

I cannot see you populating '$scope.correctAnswer' anywhere? Maybe you want to use '$scope.selectedAnswer' instead?

Tarun Dugar
  • 8,921
  • 8
  • 42
  • 79
  • So, what is the problem now? Can you recreate the problem in a plunker? – Tarun Dugar Jul 16 '15 at 10:48
  • check http://plnkr.co/edit/PmxLBb9tJ8q7OdGZwfzd?p=preview i'd created one simple demo here i'm getting result from an array but it is static one in my current question i want to fill up dynamic array on reviewans page but i'm getting null result .. getting the point ? – Nimesh khatri Jul 16 '15 at 10:52
  • I am not sure but I think after redirection the data is lost. You can use $localStorage/$sessionStorage to store data in the browser – Tarun Dugar Jul 16 '15 at 10:56
  • yap but can you give me any other kind of solution instead of session because it may cause danger for live project .. – Nimesh khatri Jul 16 '15 at 10:58
  • I suggest using a service to pass data between your controllers and maybe its best that you use a different controller for your second view. – Tarun Dugar Jul 16 '15 at 10:59
  • Nope i have only single controller for whole project and what you mean to say i didn't get can you explain please – Nimesh khatri Jul 16 '15 at 11:02
  • There is a concept called services in angularjs. Reference: https://docs.angularjs.org/guide/services – Tarun Dugar Jul 16 '15 at 11:04