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

Ways to identify whether a day is in Pacific Standard Time (PST) or Pacific Daylight

While working on setting a date in node js for my server located in IST, I am trying to figure out whether the date would fall under PDT or PST time (depending on Daylight Saving Time being on or off). If my server was in PST/PDT time zone, this decision ...

How to move a div beneath the JavaScript files in Drupal 7

I am facing a challenge where I need to position a div right above the body tag without interfering with the scripts located above it. Despite my efforts, I have not been successful in achieving this goal. I attempted to use Hook_page_build to position t ...

Attempting to create a functional action listener for a deck of cards game

I'm currently working on a game and want to make an image appear blank when clicked on, to simulate it disappearing. Specifically, this is for a tri peaks solitaire game. I have a function that tests the validity of playing a card, but I'm strugg ...

How can I verify if a date is after the current date using Node.js?

I am struggling to set up date validation that ensures the date is after the current date. This is what I have attempted so far: Router.post('/home', [ check('due_date') .isDate() .isAfter(new Date.now()) .wi ...

Trouble retrieving desired data from an array of objects in React Native

I'm having trouble retrieving values from an array of objects in my state. When I try to access the values, it only prints out "[Object Object]". However, when I stored the values in a separate array and used console.log, I was able to see them. Here ...

What is the best way to arrange an array of objects in JavaScript by numerical order and then alphabetically?

Possible Duplicate: Sorting objects in an array by a field value in JavaScript I'm looking to sort an array of objects both numerically (by id) and alphabetically (by name). However, the current method I'm using is not giving me the desired ...

Different methods for testing AngularJS directives

Currently, I am developing a Rails 3.2 application that will utilize AngularJS. While I have successfully implemented the desired functionality using AngularJS, I am facing challenges when it comes to testing my code. To run Jasmine specs, I am utilizing g ...

Using ng-repeater to create a ui-grid within ui-tabs

I have a simple user interface tab with a grid, but when I switch tabs, the page needs to be scrolled in order to see the table. <uib-tabset class="tab-container tabbable-line"> <uib-tab ng-repeat="user in vm.users" heading="{{user.user.fullN ...

Tips for concealing an entire row of a table with Jquery

I am currently working on a system that involves a table with anchor tags named original and copy in each row. By clicking on these anchor tags, we are able to update the database whether the item is an original or a copy using ajax. However, I am facing a ...

Issues arise when using ng-repeat in conjunction with ng-click

I am facing some new challenges in my spa project with angularjs. This is the HTML snippet causing issues: <a ng-repeat="friend in chat.friendlist" ng-click="loadChat('{{friend.friend_username}}')" data-toggle="modal" data-target="#chat" d ...

Error message indicating that the function is not defined within a custom class method

I successfully transformed an array of type A into an object with instances of the Person class. However, I'm facing an issue where I can't invoke methods of the Person class using the transformed array. Despite all console.log checks showing tha ...

Is it possible to submit a select menu without using a submit button within a loop?

I'm having an issue with my code that submits a form when an option in a select box is clicked. The problem arises when I try to put it inside a loop, as it stops working. Can anyone assist me with this? Below is the code snippet causing trouble: &l ...

Provide a numerical representation of how frequently one object value is found within another object value

Account Object Example in the Accounts Array: const accounts = [ { id: "5f446f2ecfaf0310387c9603", picture: "https://api.adorable.io/avatars/75/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0e6b7d7a666 ...

Eliminate the legend color border

I have successfully implemented the following code and it is functioning properly. However, I am trying to remove the black boundary color legend but am struggling to figure out how to do so. var marker = new kendo.drawing.Path({ fill: { co ...

Executing a Firebase JavaScript script on a remote web server client

I have limited experience with Javascript and I am struggling to get my code to execute. I have already completed the Android java portion, but when I attempt to run the html file, nothing happens. I am unsure if there are bugs in my code or if it needs to ...

Using JWPlayer 6 and JWPlayer 7 simultaneously in one project - how is it done?

Trying to incorporate both JWPlayer 6 and JWPlayer 7 into my expressJS, AngularJS project has been a challenge. While they each work independently without issue, bringing them together has proven to be tricky. In my index.html file, I include them separat ...

Extracting Ajax responses and storing them as variables in JavaScript

Currently, I am developing a small PHP script and using the following code for an ajax query: var CODE = $('.code').val(); var CASE = $('.code').attr('case'); $.ajax({ type:'POST', ...

The upload method in flowjs is not defined

I am a novice when it comes to flow.js and am currently using the ng-flow implementation. I have a specific task in mind, but I'm unsure if it's feasible or not, and if it is possible, how to achieve it. I've created a factory that captures ...

Oops! Looks like we couldn't locate the request token in the session when attempting to access the Twitter API

Every time I attempt to connect to the Twitter API using Passport OAuth, an issue arises that redirects me to an error page displaying this message: Error: Failed to locate request token in session at SessionStore.get (/Users/youcefchergui/Work/ESP/socialb ...

Adjust the background color of a specific list item when hovering over another list item

My dilemma lies in my inadequate knowledge to solve this issue: I have a dropdown menu embedded within a website. (View screenshot here: [SCREENSHOT]) The desired outcome is for the background color of an icon on the main list to change when I navigate to ...