Unable to retrieve information from Mat Select option

I'm encountering an issue with my code where I can see the options but cannot retrieve the value when selecting one. It just displays blank. The problem seems to be related to viewing only the status options. Does anyone have a solution to fix this?

HTML File

  <div class="main-content" *ngIf="selectedTask">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header card-header-info">
                        <h4 class="card-title"><b>Update Form</b></h4>
                        <p class="card-category">Update Task Details</p>
                    </div>
                    <div class="card-body">

                            <div class="row">
                                <div class="col-md-12">
                                  <mat-form-field class="example-full-width">
                                    <mat-select placeholder="Select Category" [(ngModel)]="selectedTask.status">
                                        <mat-option *ngFor="let s of statusChoice" >{{s}}</mat-option>
                                    </mat-select>
                                  </mat-form-field>
                                </div>
                            </div>

                            
                            <div class="col-md-4">
                            <div class="text-left">
                              <button mat-raised-button class="btn btn-success btn-block" (click)="navigateBack()"  (click)="showNotification('top','center')" (click)="updateEmployee()" ><b>Update Task</b></button>
                              </div>
                            </div>
                            </div>

                            <div class="text-left">
                            <button type="button" (click)="navigateBack()" class="btn btn-dark btn-default"><b>Go Back</b></button>
                            </div>
                            <div class="clearfix"></div>
                          
                    </div>
                </div>
            </div>

        </div>
    </div>

  


  

TS File

statusChoice=["Active","Completed","Cancelled","On Hold"];
selectedStatus: string ='';

Answer №1

The name of the variable that holds your property is selectedStatus. You have connected the mat-select to the property selectedTask.status.

Additionally, make sure to include the value attribute in the mat-option tag.

Update your code as follows:

<mat-select placeholder="Select Category" [(ngModel)]="selectedStatus">
  <mat-option *ngFor="let s of statusChoice" [value]="s">{{s}}</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

Why is it that the game board component is not appearing on my HTML page?

I am currently facing an issue with a loop in my Angular html file: <div class="board" #board> <div class="row" *ngFor="let row of this.board; let i = index"> <div *ngFor=" ...

Alert: AngularCompilerPlugin issuing warning about unexpected exit of Forked Type Checker

During development mode, I often encounter a console warning message after making code changes in my IDE: WARNING in AngularCompilerPlugin: Forked Type Checker exited unexpectedly. Falling back to type checking on main thread. The project is built on Ang ...

Timing of loading values into ng-if directive in AngularJS

While waiting for details to load, I have implemented a few ng-if directives on elements. This way, I can display a loading graphic to the user while the element value is undefined. Once the value is defined, the ng-if evaluates to false and hides itself. ...

Utilize communication channels to access electron's main process functions from the render process once deployment is complete

Hey there, I'm facing a challenge with accessing methods from my index.js main process in the render process. I've experimented with two different approaches to solve this issue. ipcMain and ipcRender Initially, I attempted to utilize ipcMain an ...

Essential front-end tools for enhancing Angular 2 projects

Hi there! I specialize in Laravel development and am currently diving into the world of Angular 2 framework. Up until now, I've been handling my third-party front end assets through bower, using a bower.json file to manage dependencies. Check out a sn ...

Is it possible to modify the express static directory path depending on the route being accessed?

I am trying to dynamically change the static path based on the route. Here is an example of what I have tried: const app = express(); const appRouter = express.Router(); const adminRouter = express.Router(); appRouter.use(express.static('/path/to/ap ...

Angular - Detecting Scroll Events on Page Scrolling Only

I am currently working on implementing a "show more" feature and need to monitor the scroll event for this purpose. The code I am using is: window.addEventListener('scroll', this.scroll, true); Here is the scroll function: scroll = (event: any) ...

Ways to modify the text of an HTML element when hovering over it

One of my elements contains the text &times; within a <span>. Is there a way to change this symbol to something else, like &infin;, when hovered over? <span class="change-text">&times;</span> When the mouse hovers over it, I ...

Tips for employing numerous if-else conditions utilizing the ternary operator in jsonpath-plus?

JSON { "customer":{ "address":{ "stateRegion":"", "stateRegionCode":"" } } } Code "address.state_code": "$.customer.address.[stateRegion ? state ...

Steps for making a toggle button with Bootstrap

Initially, I developed a web application using HTML, CSS, and JavaScript. Later on, I was requested to recreate it using Bootstrap as well. While I managed to complete the task successfully, I encountered an issue where toggle buttons in the web app revert ...

Access the web location using jQuery's ajax functionality

I need help figuring out how to post data to my "mail.py" script without knowing the URL link. Both my jQuery AJAX code and JavaScript file are located in RKProjects/scripts_js/contactform.js The Python script I want to connect to is stored in RKProjects ...

Content in Material UI Card is not aligning to the center

I'm currently working with Material UI and have successfully created a card. My goal is to center the text both horizontally and vertically within the card. However, I am facing an issue where the text remains stuck at the top of the card instead of b ...

Decorator in React that automatically sets the display name to match the class name

Is there a way to create a decorator that will automatically set the static property displayName of the decorated class to the name of the class? Example usage would be: @NamedComponent class Component extends React.Component { \* ... *\ } ...

What is the best way to set up TypeScript to utilize multiple node_modules directories in conjunction with the Webpack DLL plugin?

Utilizing Webpack's DllPlugin and DllReferencePlugin, I create a distinct "vendor" bundle that houses all of my main dependencies which remain relatively static. The project directory is structured as follows: project App (code and components) ...

Issue: Unable to set headers after they have been sent while using express-fileupload in the application

app.post('/profile', function(req, res) { // save file if (req.files) { let sampleFile = req.files.sampleFile; sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) { if (err) ...

When the enter key is pressed, shift the text to a different input field

I am facing a complex requirement How can I detect the pressing of the ENTER key within a text box with the following conditions: If the cursor is at the end of a sentence, it should create a new text box on the next row. If the cursor is in the middle ...

The border of the Material UI Toggle Button is not appearing

There seems to be an issue with the left border not appearing in the toggle bar below that I created using MuiToggleButton. Any idea what could be causing this? Thank you in advance. view image here view image here Just a note: it works correctly in the ...

What is the best way to incorporate a scroll bar into a table that updates dynamically?

If I were to create an empty table in my index.html: <body> <table width="800" border="0" class="my-table"> <tr> </tr> </table> </body> Afterward, I would dynamically add rows and columns to my-table using ...

Hiding and securing a div element when JavaScript is disabled

My form includes a <div>. This particular <div> is a red circle. Even when JavaScript is disabled, it remains visible (I can use display: none to address this). The issue arises when I re-enable JS - upon user interaction, the <div> mov ...

Acquire feedback from PHP using SweetAlert notifications

I need to update my HTML form to function like this: <script> function getName() { var name = $('#name').val(); var url_send = 'send.php'; $.ajax({ url: url_send, data: 'name=' + name, ...