The inner nested ng-repeat section is not properly binding to the scope variable and appears to be commented out

In my code, there is a nested ng-repeat set up. The 'boards' variable in the scope is an array that contains another array called 'tasks', which also consists of arrays. In the innermost ng-repeat, I am attempting to bind to task.content.

<div class="col-md-3 boards topmargin leftmargin" ng-repeat="board in boards">
            <div class="row">
                <div class="col-md-12 centerText bordered"><b>{{board.title}}</b></div>
            </div>
            <div class="row topmargin tasksContainer">
                <div class="col-md-12">
                    <p ng-init="tasks = board.tasks" ng-repeat="task in tasks" ng-init="taskIndex=$index">
                        <div>
                            <span>{{taskIndex}}</span>
                            <span>{{task.content}}</span>
                        </div>
                    </p>
                </div>
                <hr>
            </div>
            <div class="row topmargin addTask">
                <div class="col-md-12"><textarea class="addTaskField" placeholder="enter task here....."
                 ng-model="newTask.content"></textarea></div>
                <button class="btn btn-primary btn-block" ng-click="addNewTask(board)">Add Task</button>
            </div>
        </div>

This is how the 'boards' array structure looks like:

// vars
$scope.boards = [];
$scope.board={
    title: "",
    tasks: []
};
$scope.newTask = {
    content: "",
    tags: [],
    completed: null
};

I am successfully pushing the 'newTask' object into 'board.tasks' and 'board' object in the 'boards' array. Upon inspection using the debugger, the 'boards' array appears as follows:

$scope.boards = [
    {
      title : "shopping",
      tasks : [
          {
              content: "pen",
              complete: false,
              tags: []
          },
          {
              content: "bread",
              complete: true,
              tags: ['groceries']
          }
      ]
    },
    {
      title : "tomorrow",
      tasks : [
          {
              content: "go swimming",
              complete: false,
              tags: []
          },
          {
              content: "complete to-do app",
              complete: false,
              tags: ['urgent']
          }
      ]
    }
];

The issue arises where the bindings {{task.content}} and {{taskIndex}} are not displaying anything. What could be the problem?

Answer №1

There are a few things to note here:

In the comments, EProgrammerNotFound shared a link that points out <p> tags cannot contain <div> tags.

Additionally, it seems like your ng-repeat is missing the boards attribute: ng-repeat="task in board.tasks". It should be structured like this:

<div class="col-md-3 boards topmargin leftmargin" ng-repeat="board in boards">
    <div class="row">
      <div class="col-md-12 centerText bordered"><b>{{board.title}}</b></div>
    </div>
    <div class="row topmargin tasksContainer">
      <div class="col-md-12">
        <div ng-repeat="task in board.tasks" ng-init="taskIndex=$index">
          <div>
            <span>{{taskIndex}}</span>
            <span>{{task.content}}</span>
          </div>
        </div>
      </div>
      <hr>
    </div>
    <div class="row topmargin addTask">
      <div class="col-md-12">
        <textarea class="addTaskField" placeholder="enter task here....." ng-model="newTask.content"></textarea>
      </div>
      <button class="btn btn-primary btn-block" ng-click="addNewTask(board)">Add Task</button>
    </div>
  </div>

Another issue is that your <p> tag with the ng-repeat has two ng-inits. This may lead to unexpected results. You can view an example here: https://plnkr.co/edit/yJ7u4YTu2TAfhFajAjUY.

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 the conditional rendering technique in a mapped function within a React table cell

I have an array that is being displayed inside a Table, and I need to compare each object's "userName" property with the header in order to determine where to place the value. If there is no match, it should display a "0". Here is a snippet of the ta ...

Troubleshooting Ng-Switch String Length Issue in AngularJS

I'm currently developing a Store application and I have encountered an issue where I need to display two different strings based on the response received. If the response does not contain an item title, I want to display "No Item Title Found". Otherw ...

Converting an HTML div to a string for export

In the process of developing my application, I am utilizing an angular widget to construct a dynamic dashboard. Here is the snippet of HTML code along with the associated JavaScript that enables this functionality: <div class="page" gridster="gridsterO ...

The module in Node.js is unable to be loaded

Dealing with a common problem here. Despite trying to reinstall npm, deleting node_modules files and package-lock.json, the issue persists. The console output is as follows: node:internal/modules/cjs/loader:1080 throw err; ^ Error: Cannot find module &apo ...

Using Javascript to parse a regular expression in a string

I am facing a challenge with a JavaScript string that contains contact information that needs to be filtered. For example, I want to mask any email or phone number in the message. I have attempted the following approach: function(filterMessage) { ...

Having trouble downloading the Chip component in Material-UI? Learn how to fix the download issue

I used the UI to upload a file, and now I want to download it either after some time or instantly. I tried implementing this using the <Chip> component, but it's not working. I need assistance in resolving this issue. Uploaded File: const data ...

The object NativeModules from the 'react-native' requirement is currently empty

At the top of one of the node_modules utilized in my project, there is a line that reads: let RNRandomBytes = require('react-native').NativeModules.RNRandomBytes However, I've noticed that require('react-native').NativeModules ...

Is Moment.js displaying time incorrectly?

When using moment.tz to convert a specific date and time to UTC while considering the Europe/London timezone, there seems to be an issue. For example: moment.tz('2017-03-26T01:00:00', 'Europe/London').utc().format('YYYY-MM-DD[T]HH: ...

Selection of Dropdown results in PDF not loading

I am facing an issue with my function that selects a PDF from a dropdown list. Instead of loading and displaying the PDF, it only shows a blank modal. Any suggestions on how to fix this? <li> <a href="">Case Studies</a> <ul clas ...

Guide to removing a particular textfield from a table by clicking a button with ReactJS and Material UI

I need assistance with deleting a textfield on a specific row within a table when the delete button for that row is clicked. Currently, I am able to add a text field by clicking an add button and delete it by clicking a remove button. However, the issue is ...

What methods can be used to ensure the document in mongoose is not deleted by updating the expires property on the createdAt field?

I have implemented account verification in this app and created a user account that is set to delete itself after 30 seconds if not verified. createdAt: { type: Date, default: Date.now, index: { expires: 30, }, }, However, I am now searching f ...

Can you provide guidance on how to successfully transfer an array of JSON objects from the script section of an HTML file to the JavaScript

My webpage contains an array of JSON objects that I need to send to the server. The array, stored in a variable called results, appears normal when checked in the console before trying to POST it. Here is a sample of the data: 0: {id: 02934, uName: "Ben", ...

Introduction to AJAX: Conditional Statements

Within the menu.html file, there are various menu items (a href links) called menu_1, menu_2, and so on. The map.js file is responsible for displaying map content by utilizing an API to showcase different layers and maps. Even though there are many maps t ...

I am currently working on coding a function that will search an array to determine if a specific item is present. If the item is found, a variable will be set to true;

So, I have this array of prices for various items like bread, apple, noodles, beef, milk, and coke. const prices = [ ["bread", 20], ["apple", 50], ["noodles", 100], ["beef", 40], ["milk", 32], ["coke", 25], ]; And here's the JavaScript co ...

Is it possible to selectively render a page or component in Next.js 13 based on the request method?

Is there a way to conditionally render a page based on the request method in Nextjs 13? For example, when registering a user, can we show a signup form on a get request and display results on a post request? With all components now being server components ...

Limit the radio button to being clickable

Ugh, I'm really struggling with this. I want to create a quiz where only the radio button is clickable, not the text itself. Can anyone help me figure out how to do this? I have two codes below that I don't quite understand. I'll include th ...

Converting a TypeScript object into a JSON string

When working with TypeScript, I am facing a challenge while trying to initialize an object that requires a JSON string for the "options" parameter. Specifically, it pertains to the object mentioned here. It is crucial that the options parameter be in JSON ...

Tips for concealing JavaScript animations beyond specific boundaries?

So I'm delving into the world of javascript/jquery and an amazing idea popped into my head for a webpage effect. Let me break down the design a bit. My website is neatly contained within a wrapper div, ensuring that the content stays at 1000px and ce ...

Issue with Next.js Button not displaying expected result

I am in the process of developing a todo list application using next.js. The issue I am facing is that when I input data into the field, it correctly displays in the console. However, upon clicking the button, instead of the input displaying like a norma ...

Angular 1.x just got a major upgrade with the introduction of the UI-Router v1.0+ $trans

I am on the hunt for a method that can replicate the functionality of UI-Router's $rootScope.$on('$stateChange...' from before version 1.0. Although I am aware of the new $transitions service, I am struggling to get it to work in the same wa ...