I am facing an issue with accessing specific fields in an array of sections. The sections are added to the array when a user clicks on a checkbox, and the structure is defined as follows:
$scope.print = {
sections:[]
};
Once all the selected sections are obtained, I use a service to fetch a list of questions for each section by passing in an ID like this:
var questions = [];
myService.getQuestions(id)
.success(function (data) {
questions = data;
});
Subsequently, I assign these fetched questions back to the original array based on the matching QuestionSectionID like so:
angular.forEach($scope.print.sections,
function (value, key) {
if (value.QuestionSectionID === id) {
$scope.print.sections[key].questions = questions;
}
});
The assignment appears to be successful; however, I am encountering difficulties in accessing the individual field names within the questions array.
In my HTML code, I have implemented the following:
<div ng-repeat="ps in print.sections">
<div>
<h4>{{ps.vchSectionName}}</h4>
</div>
<div ng-repeat="section in ps.questions">
<div ng-repeat="q in section">
{{q.vchQuestionText}}
</div>
</div>
</div>
When trying to access the "q.vchQuestionText" field, the HTML output is blank. However, if I simply display "q" using the following:
<div ng-repeat="q in section">
{{q}}
</div>
I can see all the information present in each field of "q". My aim is to access each field in "q" by its name. Can you please guide me on what might be missing or incorrect in my approach?
Your help would be greatly appreciated!