Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have an array of sections where a section is pushed into the array when the user clicks a checkbox. It is defined like this:

$scope.print = {
  sections:[] 
};

Once I have all of the selected Sections, I use a service to get a list of questions for each selected section like this:

var questions = [];
myService.getQuestions(id)
  .success(function (data) {
    questions = data;
  });

Then I assign the returned questions to the original array like this:

angular.forEach($scope.print.sections,
    function (value, key) {
        if (value.QuestionSectionID === id) {
            $scope.print.sections[key].questions = questions;
        }
    });

The assignment "seems" to work, but I am unable to access the particular fields in the questions array by their field names.

On my HTML page, I have this:

<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 I try to access the "q.vchQuestionText" field, my HTML is blank, however if I simple do the following:

<div ng-repeat="q in section">
  {{q}}
</div>

I can then see ALL of the information contained in each field of "q". But I need to access each field in "q" by it's name. What am I missing here?

Any assistance is greatly appreciated!

share|improve this question
    
Can you give some sample data? – Pritam Banerjee 21 hours ago
    
What exactly do you wish to see? $scope.print.sections is an array of sections. Each Section has an id, and a name. The questions array contains about 30 fields. – Rani Radcliff 21 hours ago
    
In js you have sections array with nested Questions array, but in html you use ngrepeat for Questions first and name each section – Layonez Wronskey 21 hours ago
    
I'm not sure what you mean. The first ng-repeat is "ps in print.sections", the second one "section in ps.questions" gets the questions. – Rani Radcliff 21 hours ago
    
A section obviously contains more than an id and a name. It contains QuestionSectionID and vchSectionName. Maybe that's what you mean by "id and a name", but asking volunteers to guess at your data model will lead to confusion. Also, naming is important; you have section in ps.questions... why is that not question in ps.questions, since ps appears to be a section itself? – Mike McCaughan 21 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.