How can a string array object be passed as an argument into the constructor of a class when creating the object?

When instantiating a class object, what is the best way to pass a string array as an argument into the constructor?

export class ManagerComponent {
    private selectedFilters: SelectedFilters;
    public ngOnInit() {
        this.selectedFilters = new SelectedFilters(new String[]);
    }
}

export class SelectedFilters {
    constructor(public related: String[]) { }
}

Answer №1

If you want to start an array, simply type [ values ]:

this.chosenItems = new ChosenItems(['Example']); // Array containing a string
this.chosenItems = new ChosenItems([]); // Blank array

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

Angular: Update form control validation when another form control changes

If you want to view the project in a stackblitz, please click here. In the project, there is a reactive form with controls named firstNumber, secondNumber, and thirdNumber. The validation requirement for the form control thirdNumber is that its value shou ...

Angular2 - Transmitting validation information from parent component to child component input validation

I am currently developing an automatic word correction module using Angular2. Within my child component, I have set up an EventEmitter. import {Component, Input, Output, EventEmitter} from '@angular/core'; ... export class StudyThumbsComponent{ ...

Using Angular4: Binding to the result of a function in ngFor loop

Consider the following code snippet: <div *ngFor='let loc of user.locations | async'> <div *ngFor='let day of days'> <div *ngFor='let data of get_data_observable(loc, day) | async'> . ...

I can see my Angular 2 object displayed on the console, however, the specific properties are not showing up in the template

Below is the template and component code snippet that I am working with: Template: <div *ngIf="newJobCreated"> <h3>Name: {{newJob.name}}</h3> <h3>Job: {{newJob.job}}</h3> <h3>ID: {{newJob.id}}&l ...

Is there a method to reduce the requirement for if-conditions in this situation?

After revisiting this previous inquiry, I successfully implemented multiple filters on my observable, based on the user's chosen filters. However, the issue arises from the uncertainty of whether a filter is applied and the varying behavior of each f ...

Unlocking the power of Paystack: Integrating Paystack options into your Angular4-paystack button

I am transferring options from my controller.ts file: this.options = { key: this.key, plan: response.responseData.plan_code, email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e4b4 ...

Converting an Observable<boolean> to a boolean value in RXJS without subscribing

How can I transform an Observable into a boolean value? Is there a common operator that can achieve this task? I've looked for solutions but haven't come across any. Appreciate the help. ...

steps for setting up firestore database

Hey there, I'm trying to retrieve data from Firestore within a cloud function. To initialize Firebase, I have a file called firebase.ts: import * as admin from "firebase-admin"; import { getFirestore } from "firebase-admin/firestore&quo ...

React-Bootstrap columns are not displaying in a side by side manner and are instead appearing on separate lines

I am currently integrating Bootstrap into my React project alongside Material UI components. Below is a sample of one of my components: import { styled } from "@mui/material/styles"; import Paper from "@mui/material/Paper"; import Cont ...

Discovering JSON data in Angular 4

I am working with a JSON data format retrieved from (this.url) { "user": [ { "id": "1", "name": "root", "password": "root" }, { "id": "2", "name": "clienttest", ...

The ActivatedRoute.routeConfig object appears to be empty in an Angular 2 project built with Angular-cli

Two projects I've created using angular-cli are working perfectly fine. However, in one of them, the routeConfig is showing as null and I can't figure out what's causing this issue. Both projects have identical package.json files, so there ...

Retrieve a HashMap through an HTTP GET request using Angular 10

I am currently using the following versions: Angular CLI: 10.0.1 Node: 12.18.2 OS: win32 x64 Angular: 10.0.2 In my setup, I have a Java Spring Boot service that is functioning correctly and returns data as a HashMap. Map<String, List<String>&g ...

Preventing image flickering in SvelteKit: A guide

Upon the initial loading of a website, you may notice that the images tend to flicker or flash when transitioning between them. However, once these images are stored in the browser's cache, subsequent visits to the site will display the images seamles ...

Ways to extract additional information beyond just the 'Webpack Compilation Error' while using Cypress

Every time an error occurs in one of my imported modules, Cypress only provides the vague message Error: Webpack Compilation Error. It's frustrating not to have a useful error stack to troubleshoot the issue. Is there a way to access more detailed err ...

There appears to be no overload that aligns with this call using styled components (index.d.ts(2187, 9))

Trying to create an Input component using styled components that accepts props but encountering an error when using the onChange prop - No overload matches this call. It seems like there might be an issue with my types, but even after extensive research, I ...

Ways to determine the current active tab in React are:

Currently, I am facing an issue with my code involving two tabs. Upon clicking on the second tab, I want to display a specific message. However, I am struggling to determine when the second tab is selected. The main problem lies in the fact that the selec ...

Tips for monitoring changes to files while developing a NestJs application within a Docker container

Having an issue with NestJS and Docker here. Trying to run the development script using npm start: dev, but encountering a problem where the app runs fine but doesn't detect any changes in the source files, hindering the development process. Here&apo ...

Injecting a service into a base class in Angular, but not in the sub-class, then utilizing the parent service in the sub-

When working with Angular 7 and Typescript, I have a base class that relies on multiple services and has around 40 subclasses. Instead of adding these services to each subclass constructor and passing them to super(), I am looking for a more efficient wa ...

A step-by-step guide on creating a user-specific signature in Node.js

Is there a way to incorporate user-generated signatures similar to how Amazon delivery personnel have recipients sign on their mobile devices using NodeJS? Any helpful resources would be greatly appreciated. I am working with Angular for the frontend and ...