Ways to display all information from various ng-repeats in a table

Hey everyone, I am encountering an issue with ng-repeat and need some help with the following code snippet. Basically, I am trying to display all the data in three steps: 1. Displaying the name using ng-repeat-start. 2. Showing the questions with ng-repeat. 3. Displaying the answers using ng-repeat again. The problem I am facing is that after implementing ng-repeat for displaying answers, the name and questions are not showing up. How can I resolve this and display all the data correctly?

1. Name/Title // currently not showing => should be displayed
2. The Questions // currently not showing => should be displayed
3. Answers => 1 2 3 4 5 // currently showing

Thanks

var $scope;
var app = angular.module('miniapp', []);

function Ctrl($scope) {
    $scope.instructors = [{
        id: 1,
        name:"A",
        questions:[
            {"ask":"what is apple?"},
            {"ask":"what is apple1?"},
            {"ask":"what is apple2?"}
        ]
     
    }, {
        id: 2,
        name:"B",
        questions:[
            {"ask":"what is pier?"},
            {"ask":"what is pier1?"},
            {"ask":"what is pier2?"}
        ]
    }
    , {
        id: 3,
        results:[
            1,2,3,4,5,6,7,8,9,10
        ]
    }
  ];
}
  table {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

<div ng-app="miniapp">
    <div ng-controller="Ctrl">
         <table class="table table-striped table-border">
                      <tr ng-repeat-start="DataQuest in instructors">
                        <tr ng-repeat="a in DataQuest.questions">
                          <tr ng-repeat="b in DataQuest.results track by $index">
                          

                            <td ng-if="!$first"></td>
                            <td ng-if="$first">{{DataQuest.name}}</td>
                            <td>{{$index + 1}}</td>
                            <td>{{a.ask}}</td>
                            <td>{{b}}</td>
                            <td>{{b}}</td>
                            <td>{{b}}</td>
                            <td>{{b}}</td>
                            <td>{{b}}</td>
                            
                      <tr ng-repeat-end></tr>    
                        </tr></tr>                    

                  </table>
    </div>
</div>

Answer №1

Here is a fiddle that I have created, although it may not be perfect for your needs,

it could provide some assistance to you.

Feel free to take a look at this fiddle.

ng-repeat inside of ng-repeat

<tbody ng-repeat="question in instructors track by $index">
    <tr ng-repeat="ask in question.questions track by $index">
        <td>{{question.name}}</td>
        <td>{{$index+1}}</td>   
        <td>{{ask.ask}}</td>
        <td>{{b}}</td>
        <td>{{b}}</td>
        <td>{{b}}</td>
        <td>{{b}}</td>
        <td>{{b}}</td>
    </tr>
</tbody>

Please review the above code and let me know if it meets your requirements. :)

.

.

.

UPDATE

I have updated the fiddle with some changes. Please refer to the updated version.

ng-repeat inside of ng-repeat(2)

line 20, 21, 22, 23, 24 of fiddle

<td>{{instructors[instructors.length-1].results[instructors[$parent.$index-1].questions.length + $index]}}</td>

This segment of code helps calculate the index of 'results' and fetch its corresponding value.

It might seem complex, but I have made assumptions based on the structure of the data.

Feel free to reach out if you need further clarification or assistance.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using jQuery, you can automatically close a Bootstrap modal after a certain delay

In my attempt to achieve the desired outcome, I have outlined the following steps: Show modal Wait 3 seconds Hide modal Despite implementing the code below, it does not seem to be functioning properly. What could be causing this issue? Here is the code ...

How about inputting some text into a field?

Below is the code snippet for your reference: <div class="col-xs-12 col-sm-9"> <input id="Shipping_FirstName" name="firstname" ng-model="userOrder.Shipping.FirstName" type="text" class="form-control nsg-form--input ng-pristine ng-untouc ...

Using Jquery $.ajax may lead to temporary freezing of the Browser

I have a $ajax function that fetches multiple JSON objects from a URL and converts them into divs. There are around 50 objects, and I am using setInterval to call the $ajax function every 10 seconds for updates on each of the created divs. However, I' ...

Webpack unnecessarily brings in modules from nested dependencies

In my React application, the main dependencies I am using are React, react-dom, Redux, Immutable, and a few other smaller libraries. One issue I've encountered is that when I build the application with webpack, it ends up loading extra modules like lo ...

Converting a script.js document ready function wrapper and jquery plugin methods to be compatible with React (version 16.12.0)

I'm in the process of converting an older script.js file that is used to select HTML elements in conjunction with $ jquery into React. I want to export/import it into a page component using the componentDidMount() method and pass it to jquery. However ...

Generating HTML content using JavaScript object data

I have a JavaScript file that holds data in the form of objects : let restaurant_A = { name: "BBQ place", min_order: 20, delivery_charge: 5, menu: { //First category "Appetizers": { //First it ...

Tips for personalizing the Material UI autocomplete drop-down menu

I'm currently working with Material UI v5 beta1 and I've been attempting to customize the Autocomplete component. My goal is to change the Typography color on the options from black to white when an item is selected. However, I'm struggling ...

How can I conceal the _id field in this MongoDB query?

Is there a way to exclude the _id field from this query using express and node.js? I have created an API with this query, but I need to hide the _id field. Here is the query : router.get("/", (req, res) => { VerbsDE.find({}, { _id: 0 }) .limit( ...

Trouble arises when trying to load angular ui-bootstrap using require.js unless I change the name to ui.bootstrap

Code Overview: main.js: require.config({ paths: { 'uiBootstrap': '../lib/bootstrap/angular-bootstrap/ui-bootstrap-tpls.min' }, shim: {***}, priority: ['angular'], deps: ...

Performing real-time calculations for standard deviation

I am working with a set of HTML input fields labeled "textfield". I would like to calculate the standard deviation dynamically and display it in another HTML input field. Here is the JavaScript code I am using for the calculation: <script type=&quo ...

Running a Python script from an external source on a webpage through the utilization of PHP

Being new to this field with a background in Biology, I am currently focused on working with biological databases. I have successfully created a database using MySQL, HTML, PHP, and Bootstrap. However, I now aim to integrate an analysis module that include ...

Model with a CRUD structure that includes a nested model

I'm in the process of developing a CRUD functionality for my application's admin panel. I've chosen to use AngularJS along with a RESTful API for this task. I have successfully managed to save a simple model, but I'm facing some challen ...

Error: The value is null and cannot be read

My external application is set up within a const called setupRemote, where it starts with the appConfig in the variable allowAppInstance. export const setupRemote = () => { if (isRemoteAvailable) { try { ... const allowAppInstance = S ...

I'm currently in the process of creating a Firefox extension and my goal is to accurately count the total number of text boxes on a webpage while excluding any hidden text boxes. Can someone please

As I work on creating a Firefox extension, I am faced with the task of counting the total number of visible text boxes on a webpage while ignoring any hidden ones. Many webpages contain hidden text fields for future use, so my goal is to exclude these fr ...

Using ES6 to generate objects within other objects

Dealing with data from a local API can be challenging, especially when you have limited control over the incoming data. However, I am looking to transform the data post my API call using a custom function. This is my current approach transformArray = () ...

Error message encountered: Failed to convert 'text' to a string using Selenium webdriver

As a beginner in selenium, I have recently set up my environment with the latest versions of selenium web driver 3.4, Node.JS v8.2.0, and the gecko driver. I have also configured my environment variables. Currently, I am writing my tests using Visual Stud ...

Deliver ui-router resolved data to controllers without the need for direct injection

In my current project, I am developing an Angular 1.5 application that heavily relies on ui-router functionality. Our state definitions are structured like this: $stateProvider .state('jobs', { url: '/jobs', template: ' ...

What is the process of establishing intricate data connections between AngularJS and Firebase?

I am currently developing an AngularJS application with a Firebase backend. In the database structure, there is a section dedicated to students which includes their first name, last name, and schedule with courses. Student - FirstName - LastName - Schedul ...

What sets apart a local node.js server from a basic python http server?

I am currently in the process of creating a D3.js chart on my local machine. Both my csv file and index.html are located in the same folder on my Desktop. Everything runs smoothly when I use my python local server, but I encounter issues when attempting to ...

Add the file to the current directory

As a newer Angular developer, I am embarking on the task of creating a web page that enables users to upload files, with the intention of storing them in a specific folder within the working directory. The current location of the upload page component is ...