What could be causing me to receive an array of undefined objects when attempting to utilize subscribed data in my component.html in Angular 6/8?

After receiving data from an API subscription, I attempted to utilize it in an ng-multiselect-dropdown. However, the ng-multiselect-dropdown only displays undefined objects as options. Oddly enough, when I print the data in console immediately after subscribing, it shows the expected values.

Output: https://i.sstatic.net/4ZGYk.png

Console: https://i.sstatic.net/NVnSm.png

component.Html

<ng-multiselect-dropdown 
    [placeholder]="'custom placeholder'" 
    [data]="arr" 
    [(ngModel)]="selectedItems"
    [settings]="dropdownSettings" 
    (onSelect)="onItemSelect($event)" 
    (onSelectAll)="onSelectAll($event)">
  </ng-multiselect-dropdown>

component.ts

constructor(private db: AngularFirestore) {
    const things = this.db.collection('games').valueChanges();
    things.subscribe(data => {
      this.arr = data;
      console.log(this.arr);
    })
  }

Link to Stackblitz Demo

Answer β„–1

Make sure to correctly specify the idField and textField in the dropdown Settings.

this.dropdownSettings = {
      singleSelection: false,
      idField: "id", //changed itemId to id
      textField: "name",// changed itemName to name
      selectAllText: "Select All",
      unSelectAllText: "UnSelect All",
      itemsShowLimit: 3,
      allowSearchFilter: true
    };

This is important because your API returns an object with these attributes.

https://i.sstatic.net/7NB6N.png

See it in action here => https://stackblitz.com/edit/angular-firedemo-zdc3zk

I hope this information proves helpful!

Answer β„–2

Is it possible for you to modify the code as shown below:

constructor(private firestore: AngularFirestore) {
    const items = this.firestore.collection('games').valueChanges();
    items.subscribe((data) => this.array = data;)
  }

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

What is the best way to include a new attribute in a TypeScript internal object?

I am trying to include a property declaration in the window.history object, but I received a TypeScript error message This is my code: const historyInstance = createHashHistory(); // npm hoistory module window.history.historyInstance = historyInstance; / ...

Refining a collection of item elements by examining a string attribute, disregarding letter case differences

I'm working on a code snippet that generates item components from my list of objects (Frivillig). <app-frivillig-item *ngFor="let frivilligEl of frivillige" [frivillig]="frivilligEl"> </app-frivillig-item> Now, I have a new requireme ...

Optimizing performance in React: A guide to utilizing the Context and useCallback API in child

Utilizing the Context API, I am fetching categories from an API to be used across multiple components. Given this requirement, it makes sense to leverage context for managing this data. In one of the child components, the categories can be expanded using ...

What is the process for incorporating personalized variables into the Material Ui Theme?

In the process of developing a react app with TypeScript and Material UI, I encountered an issue while attempting to define custom types for my themes. The error message I received is as follows: TS2322: Type '{ mode: "dark"; background: { default: s ...

Received an unexpected argument count of 1 instead of the expected 0 while passing a function as a prop to a child component

I transferred the deleteImgfunc function from the insertFarmDiaryDetail component to the InsertFarmDiarySubPage component, which acts as a child component. DeleteImgfunc is a parameter-receiving function. Despite creating an interface and defining paramet ...

What is a way to perform pre-increment without utilizing the ++I operator?

It is my belief that the code snippet below: i += 1 or i = i + 1 does not have the same effect as ++i. Am I incorrect in this assumption? Is there an alternative method to achieve pre-increment without utilizing the ++ operator? ...

How to dynamically retrieve values from a const object literal using TypeScript

Currently, I am utilizing a TypeScript library known as ts-proto, which is responsible for generating TypeScript code. The resulting generated code resembles the following: //BasicMessage.ts export interface BasicMessage { id: Long; name: string; } ...

Retrieve the canvas coordinates for the images starting at lx and ending at rx on the x-axis, and

Currently, I am working on a project where I need to implement a drag and drop feature for an image within a PDF document. The goal is to retrieve the coordinates of the dragged image and use them later for document signing. The situation I am dealing wit ...

What is the best way to protect an Angular/Spring application using Keycloak?

I am seeking to enhance the security of my Spring Boot (backend) and Angular (frontend) application by implementing Keycloak for authentication. Currently, I have a simple deployment setup where the executable jar created by Spring serves both the backend ...

What is the best way to capture the inputs' values and store them accurately in my object within localStorage?

Is there a more efficient way to get all the input values ​​and place them in the appropriate location in my object (localStorage) without having to individually retrieve them as shown in the code below? Below is the function I currently use to update ...

Navigating Angular modules - a different perspective

I am brand new to angular routing and lazy loading modules. ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'login-admin/admin-dashboard' Error: Cannot match any routes. URL Segment: 'login-admin/admin-d ...

There are four potential types for the query variable

My node server is suggesting four possible types of query when using Typescript: string | QueryString.ParsedQs | string[] | QueryString.ParsedQs[] I am looking for a way to bypass these suggestions. While I know it's possible to ignore or parse thes ...

Guide on setting an instance property through a callback function triggered by the instance

I am looking to set an attribute of an angular service using the result from a callback function. Here is my Angular service: @Injectable() export class SkillsManagerService { private skill: any; private event: any; constructor() { ...

NG8001: The element 'app-servers' is unrecognized

Oh no! https://i.sstatic.net/fzYWO0w6.png Issue https://i.sstatic.net/xGunjgiI.png https://i.sstatic.net/26gzDLJM.png I've tried everything but can't seem to fix it I'm using the same selector but the problem persists It's supposed ...

Angular's dependency injection gets disrupted by the use of lazy loading

I am facing a scenario where I have a module A, which is an npm package that needs to be used in module B. Module B is also an npm package that is utilized in an application. Module B is lazily loaded by the application. Within module A, I have the follo ...

Enabling local host API requests while maintaining Content-Security-Policy restrictions

My recent exploration led me to electron, which I utilized to develop a Windows app for my ionic-angular web application. I am eager to make API calls to a localhost API. Up until now, I have resorted to simply deleting the Content Security Policy using ...

Incorporate Typescript into specific sections of the application

I've got a Node.js application that's entirely written in JavaScript. However, there are certain sections of my app where I'd like to utilize TypeScript interfaces or enums. Is there a way for me to incorporate Typescript into only those s ...

Issue with code coverage details not being displayed when running the command "ng test --code

I'm having trouble with the code coverage results when running the tests using ng test --code-coverage. The coverage is coming back as unknown and I'm not sure what's causing this issue. Any assistance would be greatly appreciated. > ...

File upload not functioning correctly with Angular 7 MEAN stack when using multer middleware

I am currently using the multer middleware for file upload in my Angular mean stack project. However, I am facing an issue where I am unable to retrieve req.file but can successfully access req.body, indicating that the file is not being uploaded. When I c ...

Saving any type of file in SQL Server with a field type of varbinary(max) can be achieved by utilizing Angular with ASP.NET Core to create a REST API

I am currently facing an issue while attempting to save a file, such as an image, in the Microsoft SQL Server Management Studio through asp .NET core for the Rest API. I have managed to create a base64 representation of the file, but I am unsure about the ...