Receiving an error in Angular 5 that says a differ cannot be found to support the object '[object Object]' of type 'object'

Representation of the result object

data: { "23":
       { prop: abc, prop_2: def },
        "78":
       { prop: abc, prop_2: def },
       "2098":
       { prop: abc, prop_2: def },
      }

Sample Code Snippet

<div *ngFor="let filterCar of data">
     // your code here
  </div>

Answer №1

To convert your object into an array of objects, use Object.values method:

let newArray = Object.values(object);

After that, you can loop through the array using ngFor directive

<div *ngFor="let item of newArray">
 // Your code here
</div>

Answer №2

When it comes to calling *ngFor, keep in mind that it works only on arrays, not objects. To make your object compatible with ngFor, you'll need to convert it into an array using Object.entries:

const arrayOfObject = Object.entries(data);

After converting the object, you can then use *ngFor to iterate over the new array:

<div *ngFor="let item of arrayOfObject "></div>

For more information about Object.entries(), refer to MDN Object.entries().

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

The 'MY_EVENTS_LOAD' argument is incompatible with the 'TakeableChannel<unknown>' parameter in the yeild takeLatest function

I am encountering a TypeScript error while using Redux and Saga as middleware. The error message is as follows: No overload matches this call. The last overload gave the following error. Argument of type '"MY_EVENTS_LOAD"' is not assignabl ...

Utilizing TypeScript to match a data object's type field to corresponding React Components

Our content is organized in a (tree) structure of nodes, each with its own type type NodeType = "text" | "image"; interface Node<T extends NodeType> { type: T; } To simplify things, let's say the content we receive is not ...

Angular Select Component with Input Value

In a small part of my code, I have a select tag with multiple option elements. This allows me to loop through the elements and select the one that I require. The tricky part is that I need to implement a search functionality within this select. Essential ...

The Vuex MutationAction decorator cannot be assigned to a TypedPropertyDescriptor

I am a beginner in Typescript and apologize in advance if this is a rookie mistake. I am struggling to resolve this TS error: @Module({ namespaced: true, name: "Admin" }) class Admin extends VuexModule { public adminUserList: UserList = []; ...

Is there a way to show text as symbols in Primeng components?

Check out this helpful example that demonstrates what I am attempting to achieve. I have implemented p-menu from primeng. Is there a method to convert text into symbols like &trade to ™ and &#8482 to ®? ...

WebStorm is not implementing the exclude option as specified in the tsconfig.json file

Is there a way to exclude a directory from TypeScript compilation in WebStorm? Despite specifying the exclusion in the tsconfig.json file, it seems that WebStorm doesn't respect the setting and compiles everything in the root directory. However, runn ...

Conditional rendering with Angular's ngIf directive may fail to work properly when the value being evaluated contains a

When comparing values, *ngIf does not work properly if the value/data contains a hyphen (-) symbol, like 'Pick-list' in my example. If I remove the hyphen symbol, then it works. So how can I compare strings that contain a hyphen symbol? not w ...

Tips for invoking a function from a different component in Angular?

I'm currently working on implementing a method call from one Angular component to another Inside one.component.ts, there is a task to verify if it's a day off export class CalendarComponent implements OnInit { isDayOfWeekDisabled(dayOf ...

Ensure that function and class names are retained in the optimized build for Angular 8 to allow for reflection purposes

In an attempt to configure my Angular 8 project build in a way that preserves function and class names (necessary for utilizing reflection and other class name-based features), I have turned to @angular-builders/custom-webpack which allows for overriding w ...

Example of Using Bluebird in a Chain of Catch and Then Functions

I am struggling to understand how promises work in my code flow setup. I want to create a register function with multiple steps, but I'm unsure of what is achievable and what is not. Imagine I have a register function where I need to: register a u ...

Error encountered in Typescript while attempting to $set a subdocument key value in MongoDB

This is a sample data entry. { _id: ObjectId('63e501cc2054071132171098'), name: 'Ricky', discriminator: 7706, registerTime: ISODate('2023-02-09T14:23:08.159Z'), friends: { '63e502f4e196ec7c04c4 ...

The MUI DataGrid's onCellEditStop event triggers when a cell's value is

When using MUI DataGrid, I encountered an issue where the value of a previously edited cell changes when editing another cell. I read that using onCellEditCommit as a solution, but since it's deprecated, I'm seeking an alternative fix. const ha ...

Oops, there was an error: Sorry, but we couldn't find any routes that match the URL segment 'edit/2'

My Angular4 app is functioning well, but I encountered the following error: :1440 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'edit/2' Error: Cannot match any routes. URL Segment: 'edit/2' at A ...

How should one properly deal with this situation when it comes to the 'ngChanges' function?

Providing a downloadable data to a child component using the @input value has been working smoothly. Users can click on the download link and the file is downloaded without any issues. However, when changes are detected and the ngOnChanges function is tri ...

Angular efficient approach to changing object properties

When working on creating or updating records, I encounter a problem with the length and cleanliness of my code. The dealTypeValues object varies based on the dealDispositionType (buyout or sale), resulting in lengthy and messy code. Does anyone have sugge ...

Unleashing the power of Angular 7+: Extracting data from a JSON array

As a newcomer to Angular and API integration, I am facing a challenge in fetching currency exchange rates data from the NBP Web API. The JSON file structure that I'm working with looks like: https://i.stack.imgur.com/kO0Cr.png After successfully ret ...

Discover and showcase individual product information using Product ID in Angular 8 with Firebase integration

I've been struggling to retrieve a single product record from Firebase using Angular 8. I'm new to this and have spent the past two days trying to figure it out. Below is my Firebase database. I have all products displayed on one page, and when c ...

Navigate Formik Fields on a Map

Material UI text-fields are being used and validated with Formik. I am looking for a way to map items to avoid repetitive typing, but encountering difficulties in doing so. return ( <div> <Formik initialValues={{ email: '&a ...

Error: Failed to fetch the data from the Firebase database

I have recently added an edit button to my product list, but when I click on it, the form page opens with no data populated. Upon debugging in my product.service.ts file, I noticed that it outputs null when using console.log(p). I believe this is where the ...

How to retrieve a variable from an object within an array using AngularJS code

I recently started learning TypeScript and AngularJS, and I've created a new class like the following: [*.ts] export class Test{ test: string; constructor(foo: string){ this.test = foo; } } Now, I want to create multiple in ...