A list is received as a parameter by the component

I am encountering an error while trying to pass a list of objects to my component. The specific error message is:

compiler.es5.js:1694 Uncaught Error: Template parse errors:
TypeError: Cannot read property 'toUpperCase' of undefined ("
  </a>
  <ul class="dropdown-menu">
      <li [ERROR ->]*ngFor="let item of {{items}}">
        <a href="#paper">{{item.id}}</a>
      </li>

In dropdow-cp.component.ts:

export class PfDropdownComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

@Input() items;

}

In dropdow-cp.component.html:

<div class="dropdown">
  <ul class="dropdown-menu">
      <li *ngFor="let item of {{items}}">
        <a href="#paper">{{item.id}}</a>
      </li>
  </ul>
</div>

In dashborad.component.ts

import { Component, OnInit, Input } from '@angular/core';

@Component({
    selector: 'dashboard-cmp',
    moduleId: module.id,
    templateUrl: 'dashboard.component.html'
})

export class DashboardComponent implements OnInit{


  @Input() lista = [
    { id: 11, name: 'Mr. Nice' },
    { id: 12, name: 'Narco' },
    { id: 13, name: 'Bombasto' },
    { id: 14, name: 'Celeritas' },
    { id: 15, name: 'Magneta' },
    { id: 16, name: 'RubberMan' },
    { id: 17, name: 'Dynama' },
    { id: 18, name: 'Dr IQ' },
    { id: 19, name: 'Magma' },
    { id: 20, name: 'Tornado' }
  ]

}

In dashborad.component.html

{{lista}}

    <pf-dropdown items="{{lista}}"></pf-dropdown>

The issue I'm facing is that when calling the {{lista}}, it does not display any content and remains empty.

Answer №1

To display a list of items, use

<li *ngFor="let item of items">
along with
<pf-dropdown [items]="lista"></pf-dropdown>

Avoid using interpolation ({{}}) as ngFor automatically treats your statement as an expression and checks for an array in either your template or component class (.ts file).

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

Encountering a 401 Unauthorized error in Angular despite successfully logging in with ASP.NET CORE

I have implemented a login feature in Angular. Once logged in, I receive a JWT key. However, I am facing an issue when trying to retrieve a list of clients from my API after logging in. I am following the instructions provided at this link. I am puzzled as ...

The concept of public property remains ambiguous within the Map operator in Typescript

I have implemented the following code snippets: isValidLogin():Observable<boolean> { return this.http.get(this._checkLoginUrl) .map(res=>res.json()) .map((res) => { if (res.success) { this.loggedI ...

What kind of index object has values that depend on the keys?

Can this kind of task be accomplished? type GeometryParams = { rectangle: { x:number, y:number, width:number, height:number}, circle: { x:number, y:number, radius:number } }; type GeometricShapes = { [shapeName in keyof GeometryParams]:{ ...

Show a dropdown menu based on a certain condition in Angular

Is there a way to conditionally display select options like this? <select id="updateType" class="form-control" formControlName="updateType"> <option value="personalDetails">Personal</option> <option value="addressD ...

Enhancing a prototype instance in TypeScript while activating strict mode

When working with an instance named remote from a factory in a vendor script, I encountered the need to add my own methods and members to that instance. While seeking a solution, I came across an insightful response on extending this in a Typescript class ...

Ways to stimulate a right-click event on an htmlelement in Angular 2

Is it possible to achieve the same functionality in Angular 2 as triggering a right-click event in jQuery? For example: ('#element').trigger({ type: 'mousedown', which: 3 }); This is similar to how you can trigger a click event like ...

The local storage gets wiped clean whenever I am using this.router.navigate

I am in the process of building a website using Angular 5 and Typescript. One important aspect of my implementation is utilizing localStorage to store the JWT Token for user login. Whenever I click on a link (either Home or any other link), I implement a ...

What could be causing the issue where only one of my videos plays when hovered over using UseRef?

I'm currently working on a project where I have a row of thumbnails that are supposed to play a video when hovered over and stop when the mouse moves out of the thumbnail. However, I've encountered an issue where only the last thumbnail plays its ...

The data type is expanding to encompass the entire enumeration

Within the provided code snippet, if the 'as' keyword is omitted in each action, the inferred type for method widens to any of the Kind types. Is there a way to prevent having to repeat 'Kind.PAYPAL as Kind.PAYPAL'? enum Kind { CAS ...

Transmitting a base64 data URL through the Next.js API route has proven to be a challenge, but fortunately, other forms of

It's frustrating me to no end. I've successfully done this before without any problems, but now it just won't cooperate. Everything works fine when passing an empty array, a string, or a number. However, as soon as I include the data URL, t ...

What is the best way to divide text into key-value pairs using JavaScript?

I have data in text format from my Raspberry Pi that I need to insert into MongoDB as key-pair values or JSON for my Node.js Application. I'm relatively new to JavaScript and I'm looking for a solution. Any suggestions would be greatly appreciate ...

Adjusting the audio length in React/Typescript: A simple guide

I'm currently developing a web app with React and TypeScript. One of the components I created is called SoundEffect, which plays an mp3 file based on the type of sound passed as a prop. interface ISoundEffectProps { soundType: string, // durat ...

Encountering a Windows 11 issue: npm ERR! errno -4058 with ENOENT bash code

Encountered a troublesome NPM issue suddenly, after taking a brief break from working on my project. Facing the following error with core-js. npm ERR! code ENOENT npm ERR! syscall spawn bash npm ERR! path C:\Users\User1\Documents\projec ...

The error message states that the property 'id' is not found on the 'User' type when using Passport and Typescript

When I try to access req.user.id while using PassportJS in Express with Typescript, I encounter the following error: Property 'id' does not exist on type 'User'.ts(2339) Upon logging req.user to the console, the id property is clearly ...

I was able to use the formGroup without any issues before, but now I'm encountering an error

<div class="col-md-4"> <form [formGroup]="uploadForm" (ngSubmit)="onSubmit(uploadForm.organization)"> <fieldset class="form-group"> <label class="control-label" for="email"> <h6 class="text-s ...

What mistake am I making in my Typescript + React code that is causing the error "TypeError: {array of objects).map is not a function" to

I have been developing my personal blog using Nextjs and have encountered an issue with rendering posts on two specific pages: Homepage - displays a select few featured posts Posts - displays all posts To mock the data, I have created a PostUtils.tsx fil ...

The authentication0 router fails to initiate navigation

I'm currently using Auth0 in combination with Angular 2. The issue I am encountering is that my login code isn't redirecting to the home page after authentication. Based on my understanding, Auth0 does not handle the redirection process itself. ...

Tips for accessing the properties of a union type function

When dealing with this scenario, What should the test() function's generic be? interface A { type: 'a' ; state: number; } interface B { type :'b', state: string; } type OneOfThem = A | B; function test<T exten ...

Exploring a Firestore collection to extract data fields for storage and utilization

I'm currently facing a challenge while attempting to access my Firestore collection and iterate through all documents to extract the valenceId field in each document. Despite trying various approaches, I keep encountering an error message stating: "c ...

Guide to setting up front-end code coverage in SonarQube for an Angular application

Here is my dashboard in Bamboo regarding Sonarqube: https://i.sstatic.net/FU7c9.jpg This is how the project build result page appears: https://i.sstatic.net/DRltU.jpg I am looking to integrate test coverage in Bamboo to view unit test reports, as we alre ...