Interpolating strings with Angular does not result in binding

My goal is to populate the template using string interpolation. However, when I attempt to reference the variable in the template, I receive the following error:

core.js:1350 ERROR TypeError: Cannot read property 'status' of undefined.

HTML code:

<div class="chat-main">
    <div class="col-md-12 chat-header rounded-top bg-primary text-white hide-chat-box">
        <div class="row">
            <div class="col-md-6 username pl-2">
                <h6 class="m-0">&nbsp;&nbsp; &nbsp;Tasks</h6>&nbsp;
                <span class="badge" style="background: red">{{ task?.status?.length }}</span>
            </div>
            <div class="col-md-6 options text-right pr-2">
                <i class="fa fa-window-minimize" aria-hidden="true"></i>
            </div>
        </div>
    </div>
    <div class="chat-content">
        <div class="col-md-12 chats border">
            <br/>
            <ul class="p-0" *ngFor="let task of tasksRes">
                <li class="pl-2 pr-2 text-dark send-msg mb-1">
                    <div>
                        <a href="javascript:;" [routerLink]="[task.link]" style="text-decoration: none !important;">
                            <span class="text-warning" *ngIf="task.status == 'In_progress'"><i class="fa fa-spinner fa-spin"></i></span>
                            <span class="text-success" *ngIf="task.status == 'Done'"><i class="fa fa-check"></i></span>
                            <span>&nbsp;&nbsp;{{ task.name }}</span>
                           </a>
                        <br/>
                        <span class="pull-right text-muted">{{task.createdDate | timeAgo}}</span>&nbsp;&nbsp;
                        <span class="text-muted">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{task.eventType}}</span>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</div>

Answer №1

task is a local variable scope that is only accessible inside the `ngFor` template, specifically within the ul element.

Please ensure that the span element is moved inside the `ngFor` template.

<span class="badge" style="background: red">{{ task?.status?.length }}</span>

Learn more about NgFor Local Variables

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

Why is it that GetElements does not provide immediate results upon execution?

Just diving into the world of Javascript for the first time and experimenting with it on Chrome, but running into unexpected results. When I try: document.getElementsByTagName("h1") I anticipate seeing: <h1>tester h1 in body</h1> Instead, wh ...

Tips for retrieving the value of a dynamic and multi-update id using jQuery and Ajax

I'm in need of assistance with a few different tasks: Firstly, I am looking to understand how to retrieve the id of an input element when it is dynamically generated from a database. In the HTML, it displays something like field 1 -> id = "pa ...

Challenges managing errors in Angular unit tests

As I continue to learn Angular, my search for information has yielded minimal results. However, one resource that stood out was a post on Stack Overflow titled How to write a test which expects an Error to be thrown in Jasmine? After reviewing the aforeme ...

A straightforward method of transmitting data from JavaScript to the Python back-end within a Streamlit application

Utilizing the st.components.v1.iframe, I integrated an authentication system that sends a token back to the parent when a user is authenticated. The iframe content is as follows: <script src="remote/auth.js"></script> <scri ...

Tips for dynamically sending data without explicitly stating the name:

Looking to create a JSON structure with name and value pairs such as name:"john". Check out the code snippet below: var allFields = []; var inputs = document.getElementsByTagName('input'); for(var i=0; i<inputs.length;i++){ name = in ...

Retrieve information from an Express server using SweetAlert

Hi, I have created a web server using Node.js and Express. When I send a request to ip/test, it returns the text 'test' using res.send('test'). I am trying to fetch this text using sweetalert but I always encounter errors :( Here is t ...

activating the button once all fields have been completed

Currently, I am utilizing knockout.js for data binding. There is a form with fields for name, number, email, etc. If any of these fields are left blank and the save button is clicked, the button becomes disabled as expected. However, if I later fill in th ...

Transitioning from Angular 8 to Angular 9 - troubleshooting hurdles

After diligently following the official documentation to update my Angular app, I encountered several errors when running ng serve. ERROR in app/src/app/users/add/add.component.html:14:48 - error NG2345: Argument of type 'AbstractControl' is not ...

What is the best way to embed sections of one HTML page into another page?

Is there a method I can use to embed sections of one webpage within another webpage? The dilemma arises from the fact that the second page has a distinct style compared to my main page. Is it feasible to apply the alternate style solely to specific content ...

Change the data-theme using jQuery Mobile once the page has finished loading

I am facing an issue with my buttons in a control group that represent on/off functionality. Every time I click on one of the buttons to switch their themes, the theme reverts back once I move the mouse away from the button. How can I make sure that the ...

JavaScript method not properly sorting the last nested array

I am having trouble with sorting the last nested array using arr[i].sort(). Despite trying various methods such as FOR and WHILE loops along with different operators, I still cannot achieve the desired result. Can someone help me identify what I am doing w ...

The custom pattern validation for Formly Email is malfunctioning

Is there a way to validate email input using ngx-formly? I attempted the code below but it didn't work as expected app.module.ts export function EmailValidator(control: FormControl): ValidationErrors { return /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a ...

Retrieve Gridview properties using JavaScript

I need to adjust the font size of my gridview using JavaScript to make it more suitable for printing. What is the best way to change the font size specifically for a gridview using JavaScript? ...

Tips on ensuring a <video> element occupies the full height and width of the screen

I am currently working on an Angular 6 project where I am live streaming a user's webcam to an HTML element. My goal is to simulate the experience of capturing a video or photo on a mobile device. However, the size of the video is currently small. I ...

What could be causing the format to be incorrect?

docker run -it -v "%cd%":/e2e -w /e2e cypress/included:6.2.1 --browser chrome When attempting to execute this command within Visual Studio Code, an error is encountered: docker: invalid reference format. See 'docker run --help' Vario ...

The functionality of activating a button is not functioning as expected in AngularJS framework

Next to the question I have linked here, I am exploring a different approach. As a beginner in AngularJS/Cordova/Ionic, my goal is to achieve different outcomes when the "Eingepasst" button is clicked, each with unique logic compared to "Gewonnen" or "Ver ...

Dynamically Loading External JavaScript Files Depending on User Input

Looking for guidance on how to dynamically load a single javascript file out of several options based on user input in an HTML code. Any suggestions on how to achieve this task? Thank you! ...

Tips for showcasing images stored in Azure Blob storage

Currently, I am developing an application that requires loading images from a web novel stored in Azure Storage Accounts as blobs. While I have enabled anonymous reads to show the image upon request successfully via a web browser or Postman, I am facing an ...

Creating a classification for a higher order function

In the code snippet below, I have a controller that acts as a higher order method: const CourseController = { createCourse: ({ CourseService }) => async (httpRequest) => { const course = await CourseService.doCreateCourse(httpRequest. ...

Resolve problems with implementing dynamic routes in Next.js

I have been learning about Next.js and I am struggling with understanding how to set up dynamic routing. I have the following setup: https://i.stack.imgur.com/uBPdm.png https://i.stack.imgur.com/YYSxn.png "use client" import React from "reac ...