Problem with Primeng multiselect not displaying selected values

I am currently facing an issue with populating options on a p-multiSelect element.

The HTML code in question is:

<p-multiSelect
  name="ambits"
  [options]="scopes$ | async">
</p-multiSelect>

The variable scopes$ is defined as follows:

public scopes$: Observable<Array<ApplicationScope>>;
constructor(
    private service: AplicacionsSubcomponentService
) {
    this.scopes$ = service.getScopes()
        .pipe((take(1)));
}

However, despite setting up the

Observable<Array<ApplicationScope>>
subscription using async, my multiselect options remain empty.

Any suggestions on how to resolve this issue?

Answer №1

It seems like the issue lies in how you are calling your services. The AplicacionsSubcomponentService (which may have typos and should likely be corrected to ApplicationsSubcomponentService) is actually a part of your component and should be referenced using this. Try modifying it as follows:

public scopes$: Observable<Array<ApplicationScope>>;

constructor(private readonly service: AplicacionsSubcomponentService) {
    this.scopes$ = this.service.getScopes().pipe(take(1));
}

Additionally, if you want to use custom labels (PrimeNG typically looks for a property named label), you need to specify its name in the template:

<p-multiSelect name="ambits" [options]="scopes$ | async" optionLabel="name">
</p-multiSelect>

For a demonstration, refer to this working Stackblitz example. Note that a mock service was utilized in this example.

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

Creating a stepper module in Angular 6

Looking for assistance from Angular experts app.component.html <app-stepper [activeStep]="0"> <app-step [sid]="0"> <div>iam step 1</div> </app-step> <app-step [sid]="1"> <div>iam step 1& ...

Transferring information between components is made easy with ng-content

In my application, I have a set of components that are used to create cards: <app-card-container> <app-card-title>Card title</app-card-title> <app-card-body> // some content </app-card-body> </app-card-con ...

Error in Angular not providing code line numbers for debugging

There seems to be an error shown in the image below, with no line number displayed in the code and no errors appearing in the terminal. The codebase is large, and this error is occurring in the Chrome console. Clicking on the line numbers of the bundles do ...

Angular 7 ERROR: The SystemJS reference is missing

In the process of developing an Angular 7 project with systemjs for dynamic module loading, I encountered an issue. Upon attempting to utilize it, I encountered the following error: ERROR ReferenceError: SystemJS is not defined Within my package.json f ...

Error: invalid syntax found in the expression "path". This issue is specific to Angular 4

I encountered an issue while trying to utilize routerLink with a value from a property in my component. ERROR: Syntax error, unrecognized expression: /configuration/reservations at Function.Sizzle.error (scripts.bundle.js:1581) at Sizz ...

Tips for updating the display after making an angular $http request using rxjs Observables

I have a project where I am utilizing angular's $http service to fetch data from a remote endpoint. I am keen on incorporating rxjs Observables, hence the call in my service is structured as follows: userInfo() : Rx.Observable<IUserInfo> { ...

Capturing a webpage through Record RTC integration with Angular

I am looking to record a specific section of the page as a video with audio. For example, when a user enters the page, I want it to automatically start recording the activities in that particular area (similar to how iframe videos work). The recording sh ...

Arranging Objects in Angular 2 using Pipes

While I've come across similar questions, none of the solutions provided have worked for me so far. Therefore, please refrain from marking this as a duplicate unless you can point me to an answer that actually resolves my issue. Currently, I am worki ...

Can the TypeScript version be extracted from a TS file in a remote environment?

When working in a Ruby environment, you can access the defined constant RUBY_VERSION. Is there an equivalent to this in TypeScript that I can reference within a script without needing direct access to the system? I know that if I were running the code on ...

Creating a Docker Image for Node.Js Using Bazel

Reason Behind the Need I am diving into the Bazel world and struggling to find comprehensive references on constructing Docker images for Node.js. My focus lies on a Typescript-based Node.js application that relies on two other Typescript packages. My ul ...

Tips for utilizing ng-template in various components

Is there a way to display an <ng-template> in different components? For example, let's take the component test with the following structure: test.html <ng-template #content > <p> Hello world </p> </ng-template> test. ...

Innovative coding solution to modify designated variables in Angular 2 and beyond

Currently, it is possible to utilize the final script of the user which has the ability to modify certain variables that were previously accessible. I have created a simple example in vanilla JavaScript and now I am looking to achieve the same functionali ...

Error: The page you are trying to access does not have a valid default export. The provided type is not acceptable

Hello, I am a newcomer to the world of react and NextJS. Currently, I am working on a small project using NextJS 13 where I am attempting to display products stored in a JSON file (which will later be moved to a database). The application runs correctly, ...

The Ins and Outs of Selecting the Correct Module to Attach a Controller in NestJS CLI

My experience with NestJS has been great so far, especially the Module system and how easy it is to parse requests. However, I have a question about the NestJS CLI. Let's say I have multiple modules. When I create a controller using the command "nes ...

Issue: unable to establish a connection to server at localhost port 5000 while using Next.js getServerSideProps function

I am experiencing an issue with connecting to an API on localhost:5000. The API works perfectly when called from Postman or the browser, but it does not work when called inside Next.js getserverside props: mport { useEffect,useState } from "react"; i ...

Tips for capturing the observable of an initialized mat table paginator

According to the Paginator API in Material Angular's documentation, there is an initialized Observable available. This stream emits once during the directive/component's ngOnInit lifecycle hook. I am trying to figure out how to utilize this direc ...

What specific type should be used for validations when incorporating express-validator imperative validations?

Having trouble implementing express-validator's imperative validations in TypeScript because the type for validations cannot be found. // reusable function for multiple routes const validate = validations => { return async (req, res, next) => ...

Creating a JSON array or JSON object from an Angular Material table

My task is to create a JSON array or object from an Angular Material table, which I can then utilize to export to an Excel sheet. Here is the data: const ELEMENT_DATA: Element[] = [ {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: &apo ...

I encountered difficulty in testing the Angular Material Select Component due to complications with the CDK Test Harness

While working on testing a component that utilizes Angular Material Components, I came across the CDK Test Harness and decided to use it to retrieve the count of options in the Mat Select component. You can find more information about the CDK Test Harness ...

Angular 2 destroy outlet-content and refresh the view

Is there a method in Angular 2 to remove a component that was automatically created within a router-outlet? I am looking to destroy it so that a new one is generated when I navigate back to that outlet (or is there a way to reload the outlet?). ...