Retrieve the $id value of a nested object using angularFire

I am facing a situation where I have to implement nested ng-repeat. While trying to retrieve the $id of the first ng-repeat, there is no issue. However, when attempting to access the $id of the second ng-repeat (highlighted in red in the image below), it returns as undefined.

The structure of my Firebase looks like this:

https://i.sstatic.net/nmIE7.png

This is the items object: https://i.sstatic.net/7CKGZ.png

Below is the HTML code and Controller:

angular
  .module('starter')
  .controller('feedController', function($scope, $firebaseRef, $firebaseArray) {

    $scope.allRequests = $firebaseArray($firebaseRef.requests);

    $scope.allRequests.$loaded(function() {
      console.log(arguments);
    })

  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<span ng-repeat="items in allRequests">   
    <!-- This works fine -->
      {{items.$id}}
      
      <div ng-repeat="item in items">
        
       <!-- Getting undefined here... -->
      {{item.$id}}
      
    </div>
 </span>

I am in need of the $id for the second ng-repeat. Any assistance on this matter would be highly appreciated.

Answer №1

To loop through your items, you can utilize the (key, value) syntax:

<div ng-repeat="(id, item) in items">
  {{id}}
  {{item.userName}}
</div>

Angularfire injects $id and $priority on the node you requested, not on all its sub-nodes. Thus, individual items do not have a $id property.

When using ng-repeat="item in items", Angular will iterate over an object's properties, ignoring those starting with $. This behavior is utilized by angularfire (otherwise, you would iterate over $id and $priority). The (key, value) in object syntax allows access to the child object's key.

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

HTML Tutorial: A Beginner's Guide to Invoking REST API

Hi there! I'm new to APIs and struggling to grasp the concept. The tutorials online seem more complex than necessary. Here's what I need help with: I want to create a basic webpage that allows me to search for information using the Pokemon API a ...

Ways to stop VoiceOver from selecting the background content when a modal is open

Is there a way to prevent VoiceOver from reading the content behind a modal? I tried using aria-modal=true, but it seems VoiceOver does not support this feature by default like NVDA and JAWS do. I found more information about this on . According to the in ...

Unable to receive data from jQuery AJAX request

I'm feeling a little puzzled at the moment. Whenever I run my ajax call, the error function is triggered every time. I am aware that the data is returning as JSON, and I have set the datatype as jsonp to enable cross-origin functionality. I am not sur ...

Formatting dates for the bootstrap datepicker

Hi there! I am currently using a bootstrap datepicker and I am attempting to retrieve the value from the datepicker text box in the format of date-month-year for my controller. However, at the moment, I am only able to obtain values in the format Tue Oct 0 ...

iOS 9.3+ causing Angular 1.5.7 Controller Scope Issues

I've been facing challenges in ensuring that my Angular 1.5.7 application successfully displays user data injected into the Scope of my Controller. While it works perfectly on various browsers in a Windows Desktop environment, it fails to display the ...

Tips for importing a different js file from an npm package without needing to include the entire node_modules path

When using the ES2016 import syntax to load the select2 library from an npm module via Webpack, everything works smoothly and the select2.js file is loaded from the node_modules directory. The node_modules directory also contains a full version of the lib ...

Using UI-Router to navigate through sections of a website

I have been working on a website that already has URLs set up using MVC. For instance, /Account directs to one page, /Customers leads to another page, and /Quotes takes you to yet another page. On the /Quotes page, there is a multi-step wizard that I am im ...

Struggling to adjust the size of d3 v6 in a React hooks environment?

I have been attempting to resize my SVG using the width and height from the state: const [svgWidth, setSvgWidth] = useState(350); const [svgHeight, setSvgHeight] = useState(250); useEffect(() => { const svg = d3 .select("#epi-char ...

Utilize jQuery and plotly.js to exclusively display newly selected items in a dropdown menu

I'm exploring plotly.js and I want to create a dynamic plot that changes based on dropdown selection. My code includes jQuery and bootstrap. However, I faced an issue where selecting a new option adds a new line to the existing graph instead of replac ...

When Sequelize is utilized with the include option, it is encountering issues by returning null values

When performing a model query with includes and there are no matching rows, the result returned includes null values. I have come across this issue multiple times before, but I have yet to find a definitive solution. Model.findOne({ where: { id: 1 }, ...

Angular navigation is inconsistent in its functionality

Currently, my Angular project consists of four components: home, portfolio, contact, and about. While I can navigate from the home page to any other component using the nav-bar, I am restricted to navigating only back to the home page when on any other pag ...

Error alert: items.appendChild does not function

I'm running into an issue while trying to add buttons to the existing list items. Below is my code snippet: function buttonDelete() { var items = document.getElementsByTagName("li"); var button = document.createElement("button"); button.appendChild( ...

Triggering a parent component function after a child component function finishes in Vue

When using Vue, I have a main component housing a child component that is loaded onto the page with a button triggering the saveTaskComment() function. Everything works perfectly until it reaches the .finally portion of the child component's function. ...

The table remains visible during an AJAX call

I need assistance with removing a table after successful deletion triggered by an AJAX to PHP call. Below is the function provided: list.php <script type="text/javascript"> function massDelete() { if (!confirm("Are you sure")) ...

What is the process of accessing JSON data transmitted from a Express server in JavaScript?

Working with a node server, I've set up a client-server model, meaning the client connects to "localhost" and express generates a response based on certain logic. While I'm able to send a JSON object through the response, I'm unsure of how t ...

Using a ternary operator within an ng-click event in AngularJS

When working with HTML, I have a button that triggers the ng-click event. Here is an example of how it looks: ng-click="!user.name : openModel('lg') ? ''" The intention here is to check if the user's name is not defined and then ...

Angular and Node.js are powerful tools for creating HTTP clients

I have been facing an issue while trying to display event data from MongoDB in an Angular view. The data shows up fine in the browser console, but it does not appear on the website itself. I am using Node.js for the backend and Angular for the frontend wit ...

Loading an HTML template dynamically into a pre-loaded div element

I need to dynamically load an HTML template into my index.html file. Now, I am looking to load another HTML template into the previously loaded template content. To clarify further: The index is loaded with a dashboard template, and the dashboard contains ...

Generating a test file for karma and jasmine controller testing

Currently, I am in the process of creating tests for the controller in my Angular application. I have a test file structured like this: describe('Controller', function() { beforeEach(module('AngularApp')); var scope, controller; ...

The server's request is being processed through jQuery's ajax functionality

Recently, I've started working with jQuery and AJAX. Essentially, the webpage sends an HTTP post request, and the server-side DLL responds by writing a JSON-formatted response back to the page. I'm trying to understand how to handle this response ...