Dropdown box not displaying any choices

I developed a basic reusable component in the following way:

Typescript (TS)

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

@Component({
  selector: 'app-select',
  templateUrl: './select.component.html',
  styleUrls: ['./select.component.css']
})
export class SelectComponent implements OnInit {
  @Input() control: FormControl;
  @Input() label: string;
  @Input() options: [];
  @Input() idAndForAttributes: string;
  @Input() customClass: string;

  constructor() { }

  ngOnInit() {
  }
}

HTML

<div class="form-group" [ngClass]="{'invalid': control.invalid && control.touched && control.dirty}">
  <label [attr.for]="idAndForAttributes">{{ label }}:</label>
  <select class="form-control" [ngClass]="customClass" [formControl]="control" [attr.id]="idAndForAttributes">
    <option value="0">- Select -</option>
    <option *ngFor="let item of options" [ngValue]="item.id">{{item.description}}</option>
  </select>
  <ng-container *ngIf="control.dirty && control.touched && control.invalid">
    <div *ngIf="control.errors.required || (control.errors.min && control.value == 0)">
      <small style="color: #c62828;">
        Value is required.
      </small>
    </div>
  </ng-container>
</div>

Currently, my goal is to utilize this component within another html file by using the code below:

   <form [formGroup]="profileActivityForm">
     <app-select [control]="profileActivityForm.get('activityType')" [idAndForAttributes]="'type'" [label]="'Type'"
                [options]="profileActivityTypes"></app-select>
   </form>

In the corresponding Typescript file (TS), I have:

 profileActivityTypes: string[] = [];

  ngOnInit() {
    this.profileActivityTypes.push('New')
    this.profileActivityTypes.push('Update')

 this.profileActivityForm = this.fb.group({
 activityType: [0]
    });
  }

However, there seems to be an issue where invisible options are being displayed as shown in this picture.

I suspect the problem lies within the HTML code of the reusable component:

<option *ngFor="let item of options" [ngValue]="item.id">{{item.description}}</option>

The error might occur due to it trying to display a description. How can I send the items as descriptions from the child component?

UPDATE

I attempted:

  profileActivityTypes: [] = [];
  ....

let profileActivities = [{ description: 'New' }, { description: 'Update' }]
this.profileActivityTypes.push(profileActivities)

Nevertheless, it throws an error upon pushing:

Argument of type '{ description: string; }[]' is not assignable to parameter of type 'never'

Answer №1

To find a solution, I decided to modify the assignment of the profileActivities array instead of creating it separately and then pushing items into it. The new approach involves directly assigning it as follows:

 profileActivityTypes = [];
   this.profileActivityTypes = [{ id: 1, description: 'New' }, {id: 2, description: 'Update'}]

I trust that this alternative will be beneficial for a wider audience!

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

incapable of altering the function of individual parts within ionic 3

I am currently working on creating a list of people for users to connect with. When a user clicks on the connect button, it should send a connection request to the chosen person. However, I am facing an issue where clicking on the connect button changes th ...

Looking to programmatically define the locale for Kendo-Ui-Datepicker element

We have integrated a locale service into our existing Angular application, which sets the locale based on a dropdown selection. This locale service is part of the angular-l10n library. After acquiring Kendo-UI for Angular, we were hoping to connect the da ...

Updating array object properties within nested for loops in JavaScript can be challenging

Exploring nested loops: for(let i = 0; i < availabilities.length; i++){ if(availabilities[i].round === 1){ // Identify objects with the same event_team_user_id and update status property let indices = helperService.findArrayIndices( ...

Troubleshooting UDP output issues in FFMPEG

Currently attempting to stream a video via ffmpeg to a udp stream by piping rawvideo directly into ffmpeg using ffmpeg.stdin.write(data). Here are my specified options/parameters: var ffmpegArgs = [ '-c:v', 'rawvideo',// input cont ...

Having trouble understanding how to display an HTML file using Next.JS?

Currently, I am working on a project that involves utilizing Next.JS to develop a webpage. The main goal is to display a PDF file on the left side of the screen while integrating Chaindesk on the right side to create a chat bot capable of extracting inform ...

What steps can be taken to address issues with the counting system in a lootbox opening

I am currently developing a virtual loot box simulator and have encountered a challenging issue. My goal is to track the quantity of Normals, Legendaries, Epics, and Rares obtained by the user. However, I am facing a problem where instead of updating the c ...

Guidance on incorporating CSS into ES6 template literals within a react framework

I am trying to implement the Material UI stepper in my React application. The step content is set up as a string literal. My goal is to include CSS styling for paragraphs within the step content. Many online resources suggest using \n to add a line ...

Creating a table with a horizontal layout using Angular Material's mat-table

I am currently utilizing angular material 8.2.3 for my website. However, I have encountered a seemingly simple issue that has me stuck. I am looking to display a table horizontally instead of vertically. In my table, I only have two columns. Below is the ...

An issue occurred while attempting to utilize fs.readFileSync

Attempting to change an uploaded image to base 64 format var file = e.target.files[0]; var imageFile = fs.readFileSync(file); var encoded = new Buffer(imageFile).toString('base64'); An error is encountered: TypeError: __W ...

Accessing the name attribute of the TextField component, displayed as a Select Box in Material-UI, by utilizing the event object received from the onFocus prop

Utilizing the "@material-ui/core": "4.11.2" library along with "react": "16.8.6", I've encountered an issue with the TextField component where the select prop is set to true. Specifically, I am unable to access ...

What is the best way to create a sign-up box that appears on the same page when you click on the sign-up button

I am interested in implementing a 'sign up' box overlay at the center of my index page for new users who do not have an account. I would like them to be able to easily sign up by clicking on the 'sign up' button. Once they complete the ...

How can I utilize React to pull information from the Google Taxonomy API?

Seeking assistance with React development, as I am a beginner and looking to retrieve data from this URL and organize it into a tree structure. I not only want to fetch the data but also display it in a tree format. My current code successfully retrieves t ...

Using Internet Explorer to watch full-screen HTML 5 videos

I am in the process of developing my own HTML 5 Browser Player. Everything seems to be working well, except for getting the full screen feature to function properly in IE 10. Chrome, Safari, and Firefox are all doing great with it. Unfortunately, my JavaS ...

Refreshing the Table to Update Data

I am working on a jquery application that includes a table with time and number fields. My goal is to increment the values every 3 seconds by creating a function to update the numbers automatically. Initially, the data in the table looks like this: Kobe ...

A step-by-step guide on using Javascript to transform images into text

Hey there! I'm looking for some help to convert an image into text. The idea is that when someone uploads an image and hits the "Submit" button, the text from the image should display in a textarea below. However, the code I've been working on do ...

Error Message: "Encountered an Issue with Angular Dynamic

I am currently experimenting with a small reference application to explore the concept of dynamically injecting components into another component in order to display content on a page. Recently, I encountered an error related to the ViewContainerRef object ...

Instantly reveal menu by pressing button

Is there a way to make my mobile menu open immediately upon touching the button? I have used ontouchstart="" in both buttons to create an overlay on the content when the offcanvas menu is visible. This functions well as soon as the user touches either butt ...

What is the correct way to navigate data through my Node.js API?

I am struggling with getting the JSON response to display at the /api/orders_count endpoint. Here is a breakdown of my setup: In my project, I have various files: Routes file - where the orders_count route is defined: routes/index.js const express = req ...

The canvas appears blank when using Firefox version 36

The application is made up of an interface (html) and workspace (canvas). We utilize three.js to create elements on the canvas. So far, it's been functioning perfectly on Chrome, Opera, and Firefox 35. You can see it in action here: However, in Firef ...

strategies for chaining together multiple observables with varying data types and operations

Hey everyone! I'm facing a situation where I have a form with multiple select types, and the options for these inputs are coming from an API. I then take the data emitted from the HTTP request observable and feed it into my FormGroup, and everything i ...