Changing the ngModel bound value based on the selection made in the mat-select dropdown can be achieved

When attempting to use ngModel to bind a value in a mat-select dropdown, I encountered an issue. The options have values like A - A/C Loss and B - BURGLARY. After checking the option checkbox, I only want to bind A and B, removing A/C Loss and BURGLARY.

Here is an example of the options values: https://i.sstatic.net/gbHt3.png And here is an example of the ngModel bound values: https://i.sstatic.net/VmRHw.png The desired result for ngModel binding should be: A,B,CF,CI,CM,CR

Example Code:

<mat-select placeholder="Select Events" [formControl]="selectEventitems" [(ngModel)]="selectedEventValue" (change)="onEventsChange($event)" (focus)="onEventfocus($event)" multiple>
     <mat-option class="select-all" value="SelectAll">Select All</mat-option>
     <mat-option *ngFor="let event of getAllEvents" [value]="event.eventrpt_id">{{event.eventrpt_id}} - {{event.descr}}</mat-option>
</mat-select>

Answer №1

Check this out

<mat-select placeholder="Choose Events" [formControl]="selectEventitems" [(ngModel)]="selectedEventValue" (change)="onEventsChange($event)" (focus)="onEventfocus($event)" multiple>
     <mat-option class="select-all">Choose All</mat-option>
     <mat-option *ngFor="let event of getAllEvents" [value]="event.eventrpt_id">{{event.eventrpt_id}} - {{event.descr}}</mat-option>
</mat-select>

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

Issue with Typescript: For in loop not identifying object properties

Currently, I am utilizing a loop with for in to iterate through a list of Meeting objects named allMeetings. Inside this loop, I am populating another list called allEvents, where non-Meeting objects will be stored. However, when attempting to access the p ...

The Vue instance seems to be unable to recognize the shims-vue.d.ts file

I encountered an issue with my Vue file. Here is the code snippet: import Vue from 'vue'; import VueRouter from 'vue-router'; export default Vue.extend({ name: 'MyComponentsName', methods: { doRedirect() { this. ...

Bidirectional object synchronization between components

I have a component containing an input: <my-input *ngIf='filter.type === checkType.INPUT_TEXT' [filter]='filter'></my-input> export class MyInputComponent{ @Input() filter: any; } The template for MyInputComponent is as ...

What is the abbreviated method of setting a default value for an optional String in Swift?

After receiving a variable from a network call of type optional String, const receivedData = data.receivedData Is there a shortcut method to construct a String using this variable and provide a default value when it's null? const finalString = "Rec ...

Creating an asynchronous reducer using ngrx: A step-by-step guide

Exploring the realm of Angular, I am delving into the creation of an asynchronous reducer to handle API calls within my application. The ultimate aim is to fetch files from an API whenever the loadFiles action is activated. In order to achieve this, I dev ...

The correlation of types between function parameters using function overloads in TypeScript

In the process of developing a factory function, I am incorporating a type argument to specify the type of object being created, along with a parameter argument containing parameters that describe the object. The parameters are dependent on the specific ty ...

Incorporate a boolean value into Ionic storage (Ionic 4) by adding a JSON object

I am looking to enhance my storage system by adding a special favorite feature. I have the ability to add multiple favorites to my storage, but only one can be designated as my top favorite! Take a look at this image for a visual representation of what I h ...

Error animation on client-side validation not resetting correctly

Incorporated a form validation and error display system utilizing TransitionGroup for animations. The flag issueVisible manages the visibility of the error message, while determineField() aids in identifying the field related to the error. The issue arise ...

Singleton Pattern in Angular Dependency Injection

In my code, I have a service called MyService that is decorated with the following: @Injectable({ providedIn: 'root' }) Part of its implementation includes: private myData: string = ''; setData(data: string) { this.myData = d ...

Connect a property of a class instance to a chain of extended class types. Instruct TypeScript to permit the behavior of JavaScript's "this"

Check out this code snippet: class Parent { constructor() { } // this method is called from child, // so 'this' is type of Child and cosmisFunc exists callChildFunction() { this.cosmisFunc() // compiler error ...

Exploring TypeScript in the world of Shopify Command Line Interface

Exploring the process of developing a Shopify app using Typescript starting with the shopify-app-cli boilerplate, which utilizes Koa for the server and Nextjs for the frontend in React JavaScript. see https://github.com/Shopify/shopify-app-cli Encounterin ...

The Nginx server seems to be having trouble reading Gzip files, despite having Gzip compression enabled

Despite having already enabled gzip compression on my nginx server, PageSpeed Insights still suggests enabling text compression for certain files. However, the mentioned files such as main.js, polyfills.js, and styles.css have already been gzipped using th ...

Request with missing authentication header in Swagger OpenAPI 3.0

When generating the swagger.json using tsoa for TypeScript, I encountered an issue. Even after adding an access token to the authorize menu in Swagger and making a request to one of my endpoints, the x-access-token header is missing from the request. What ...

"Access to root is necessary for Angular-cli to run smoothly

After installing angular-cli with the command npm install -g angular-cli, I encountered an error every time I attempted to run any ng command. The error message stated: Error: EACCES: permission denied, open '/home/m041/.config/configstore/ember-cli. ...

Set up and run a SpringBoot + Angular web application on an external IIS server

When it comes to running a Spring Boot application locally, it's as simple as running it with the spring-boot:run command or executing the main class of the project. However, deploying the same application on an IIS Server can be a bit more challengin ...

Angular not firing slide.bs.carousel or slid.bs.carousel event for Bootstrap carousel

I've searched high and low with no success. I'm attempting to detect when the carousel transitions to a new slide, whether it's automatically or by user click. Despite my numerous attempts, I have been unable to make this event trigger. I ha ...

What sets apart `this.user.id` from `this.user = {id: ....}`?

I am puzzled by the error thrown in the code below: import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-user', templateUrl: './user.compone ...

What are the best practices for managing security on your AWS Amplify web application?

When working with AWS Amplify & DynamoDB in an Angular web app, how can I secure my Amplify resources to prevent unauthorized access from external sources? An important concern lies in exposing the Amplify configuration within the Angular code, making it ...

Enhancing Lazy Loaded Modules with Angular 4.3 Interceptors

What is the recommended approach for utilizing core module services in lazy loaded feature modules and their child modules within an Angular application? In accordance with the Angular style guide, the layout of the project structure is as follows: ap ...

Problem with adding card to customer in Stripe using Angular 2 and Express

I encountered an issue while attempting to add a card to a customer. My Express server, which handles the post request to Stripe, successfully registers a new customer but fails to include credit card information for the new customer. Within my Angular 2 ...