How to push item in an empty array?


#1

The user will choose if it is correct or wrong
[Click Correct] [Click Wrong]

I want this output to show:

1.) Correct
2.) Wrong
3.) Correct
4.) Wrong
5.) Correct
6.) Wrong
7.) Wrong
8.) Wrong
9.) Wrong
10.) Correct

I want to use the pop-up message value and push it as an item to an empty array , Here is my code: can you please help me to fix it or give me some of your example ? Thank you for helping :smile:

  <input  type="radio" name="answer" value="Correct"  > Correct
 <input  type="radio" name="answer" value="Wrong"  > Wrong

<button ng-click="AddResults()">Add to list</button>

<div ng-repeat="item in items">
             {{getTotalItems()}} .) {{itemResult}}
</div>


.controller
    $scope.items = [];

$scope.AddResults = function() {
              
                 $scope.items.push({
                  ResultAnswer: $scope.itemResult,
       
             });
                 $scope.itemResult="";
           
              };

               // Get Total Items
              $scope.getTotalItems = function () {
                  return $scope.items.length;
              };

#2

if you push an object to your array you need to access the key you want in the template --> {{item.ResultAnswer}}


#3

Wow! Cool ! Thanks :smile: