Within my Angular code, I have created an array structured like this:
$scope.test = [
{'item1' : 'answer1' },
{'item2' : 'answer2' },
{'item3' : 'answer3' }
];
This array contains various items and corresponding answers.
My goal is twofold. Firstly, I aim to utilize ng-repeat to iterate through the array and display the keys along with their respective values separately. My initial attempt was as follows:
<div ng-repeat="(key,value) in test">
{{key}} = {{value}}
</div>
However, the output generated by this code does not align with what I desire. Instead of displaying as intended:
item1 = answer1
item2 = answer2
item3 = answer3
The ng-repeat currently outputs:
0 = {"item1" : "answer1"}
1 = {"item2" : "answer2"}
2 = {"item3" : "answer3"}
Secondly, I wish to use the keys from this array to fetch data from another array. For instance, consider this setup:
$scope.item1.question = 'some question';
As I traverse through the ng-repeat loop, I hope to achieve something like:
{{key}}.question
In order to display the phrase 'some question'
. Unfortunately, this particular approach does not yield the desired outcome.