Having trouble with ngFor not iterating through child properties?

Having trouble with implementing angular 2 ngFor

Defined model:

export class PaginationPage<T> {
  content: Array<T>;
}

In component:

  page: PaginationPage<Blog>;
  blogs: Array<Blog>;

  ...  
  this.blogs = page.content;

In template:

<div *ngFor="let blog of blogs">
: functioning as expected

<div *ngFor="let blog of page.content">
: encountering an issue. Error : Cannot read property 'content' of undefined

Answer №1

The reason for this is that when page.content is called, the value of page is actually undefined. To prevent this issue, you can utilize the safe navigation (elvis) operator (?):

<div *ngFor="let blog of page?.content">

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

Mastering event handling with Material-UI SimpleTable

I am trying to retrieve the rowData from an event triggered on a material-UI table component. The application I'm working on is quite simple and only requires a basic table. So far, I have tried passing event handlers to several components (Table, Ta ...

The functionality of external linking seems to be malfunctioning within Angular 2

Take for instance the website: The routing system is in place so that when you click on pages or links, the URL changes to something like: /articles /work /articles/1 However, if you were to click on this link: A 404 error is thrown. How can I configur ...

How can I export Table Tools as xls using Jquery?

Currently, I have a table that is being formatted using DataTables and TableTools. The issue I am facing is when attempting to export the table as an .xls file, it still exports as a .csv file instead. Strangely, the .pdf export function works flawlessly. ...

Deactivating the submit button after a single click without compromising the form's functionality

In the past, I have posed this question without receiving a satisfactory solution. On my quiz website, I have four radio buttons for answer options. Upon clicking the submit button, a PHP script determines if the answer is accurate. My goal is to disable t ...

attempting to access a variable which was initialized within a function in different sections of the code base

My goal is to retrieve a variable created within a function that is nested in a resize event parameter in jQuery. This variable should be dynamically updated each time the user resizes the browser window. I intend to utilize this variable to set the width ...

Experiencing a missing handlebars helper error when utilizing a helper within partials in express-handlebars

I have set up custom helpers using express-handlebars like this: const { create } = require("express-handlebars"); // Configuring the handlebars engine const hbs = create({ helpers: require("./config/handlebars-helpers"), }); app.engi ...

Learn how to showcase a predetermined option in an HTML select element using Vue.js and Minimalect

I am currently utilizing Vue.js along with the Mininmalect HTML select plugin to showcase a list of countries by their names and values, where the value represents the 2 digit country code. Successfully, I have managed to implement the plugin for selectin ...

Is it possible to reverse engineer a UI by starting from its current state and debugging backwards?

When it comes to web development, users often provide screenshots of their "invalid state". Using React, I had a thought about debugging in a different way: starting from the current state: A user sends us a screenshot of an invalid UI state. We use dev ...

Trigger function when an option is chosen from the jQuery UI autocomplete suggestion list

Hello, I have implemented an autocomplete feature in my code which is functioning properly. However, I am facing an issue where the desired function (doSomething()) is not triggered when a user clicks on an option from the autocomplete list. The function o ...

Tips for invoking a function in an ASP.NET code-behind file using JavaScript

I'm currently trying to display an image in my div by calling a function from the code behind file. The image tag is dynamically bound with JavaScript, but I'm having trouble figuring out how to call a function with parameters. The code snippet I ...

Tips for maximizing page layout efficiency without compromising on element visibility

What is occurring https://i.stack.imgur.com/Agjw6.gif The use of .hide() and .fadeIn(200) is resulting in a jittery effect that I would like to avoid. Desired Outcome When the user hovers over the menu icon, the menu icon should vanish the text "Pr ...

Tips for adding a bounding box to an image received from the server

I've got a python server that is returning a collection of bounding boxes post OCR processing (using Tesseract or similar). "bbox": [{ "x1": 223, "y1": 426, "x2": 1550, &q ...

Navigating Angular.js: finding my way to the endpoint paths

Despite my best efforts and extensive research, I find myself in need of assistance! I have a web application that utilizes node and express on the server side, with Angular on the client side. My issue lies with angular routing. IMPORTANT DETAILS My cur ...

How can you enable fullscreen for a featherlight iFrame?

I have implemented Featherlight to display an iframe within a popup modal on my website. If you click the iframe button, you can see a demo of how it works. One issue I am facing is that the generated iframe tag by Featherlight does not include allowfulls ...

Creating an instance of a class using a class decorator, with or without the 'new'

Seeking alternatives to creating class instances without using the new keyword in TypeScript, I came across this excellent solution that works seamlessly in JavaScript. The code found in the repository mentioned https://github.com/digital-flowers/classy- ...

Enhance the speed of filtering a large array of 4000+ objects in React for optimal performance

I am currently dealing with a component that generates an input of type text for filtering an array containing over 4000 objects. const { airports } = useContext(MainContext); const [airportListLocal, setAirportListLocal] = useState<Airport[]>(airp ...

When publishing, TypeScript-compiled JS files fail to be included, even though they are included during the build process in Debug and Release modes

My .NET MAUI project includes TypeScript files in the Scripts\scriptfiles.ts folder, which are compiled into wwwroot\js\scriptfiles.js. Everything functions properly until my client attempts to publish it, at which point all script files go ...

Struggling to access the height attribute from a CSS file

Hey there. I'm pretty confident that the solution to my query is quite simple. So, I have a .css file with this particular code snippet: div.site { text-align:center; border:2px solid #4b6c9e; padding:1px; margin-top:10px; font-size:medi ...

What is the best way to iterate over a JSON array object within an AJAX response using the 'each' function?

After making an AJAX call, I have a JSON object as the response. However, when I try to access an array of strings within the response, I am getting 'undefined' in return. Strangely, the console log shows that the array does exist and is populate ...

What could be the reason for the node-gyp rebuild error?

I encountered an issue while attempting to install the summarizer module. Below is a snippet of the output: npm i summarizer npm WARN deprecated <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="701c1f141103185d1e1f141530435e41 ...