Show a dropdown menu based on a certain condition in Angular

Is there a way to conditionally display select options like this?

    <select id="updateType" class="form-control" formControlName="updateType">
        <option value="personalDetails">Personal</option>
        <option value="addressDetails">Address}</option>
        <option *ngIf="{{userModalData.orgTypeCode == 'BO'}}" value="financialDetails">Financial</option> 
                  <!-- Fake Implementation -->
   </select> 

Looking for suggestions on how to achieve this. Any ideas?

Answer №1

To display certain options based on a condition, you can utilize the *ngIf directive.

<select id="updateType" class="form-control" formControlName="updateType">
 <option value="personalDetails">Personal</option>
 <option value="addressDetails">Address</option>
 <option *ngIf="userModalData.orgTypeCode == 'BO'" value="financialDetails">Financial</option> 
</select>

I have also created a Stackblitz demo for reference: Check it out here

Answer №2

Utilize the ngIf directive in this manner

 <option *ngIf="userModalData.orgTypeCode == 'BO'" value="financialDetails">Financial</option>

For further information, please refer to https://angular.io/api/common/NgIf

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

Looking for a way to dynamically append a child element within another child

Struggling to include a new child within a specific child in Json myObject:any[] = []; this.myObject = { "type": "object", "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" }, } } addF ...

Converting dates in JavaScript to the format (d MMMMM yyyy HH:mm am) without using moment.js

Looking to convert the date "2020-02-07T16:13:38.22" to the format "d MMMMM yyyy HH:mm a" without relying on moment.js. Here is one method being utilized: const options = { day: "numeric", month: "long", year: "numeric", } var date1 = new Date ...

Creating a mongoDB query that matches elements in an array of subdocuments with elements in a Typescript Array

In my database, I have stored various Events using mongoDB. Each event comes with multiple fields, including an array of genres, which consists of subdocuments like {genre and subGenre}. For instance, an event could be classified as {genre: "music", subGe ...

Unlock the File Explorer in Angular 8 by clicking on an anchor link to access and view files

By simply clicking on the anchor link provided in the application user interface, it is expected to open the server folder in the file explorer, allowing the user to access and view all the files, images, etc. In an HTML file, the code would appear as: &l ...

Revising input value post model binding

In my scenario, I have a text input that is bound to a model property of type Date: <input type="text" [(ngModel)]="model.DateStart" ngControl="dateStart" id="dateStart" #dateStart /> The value of model.DateStart (which is of type DateTime) looks l ...

Unraveling the mystery of decoding a jwt token

Every time I attempt to validate a user token, I keep encountering Error 500. function verifyToken(req, res, next) { if(!req.headers.authorization){ return res.status(401).send('Unauthorized request') } let token = req.headers.authorization. ...

Service provider not found at Injection Error and No provider error occurred

error message I am a newcomer to Angular 2. I keep encountering the "No provider for service at injection error" and "no provider error" even though I have specified the provider in the app module. The code is cribs.service.ts import { Injectable } from ...

Material Modules are causing issues with AOT compilation

I'm encountering multiple errors that all share a similar pattern: ERROR in ./node_modules/@angular/material/button/typings/index.ngfactory.js Module build failed: Error: Invalid name: "@angular/material/button" at ensureValidName (C:\path&b ...

Is there a way to retrieve all IDs within an array of objects using a foreach loop and merge the data associated with each ID?

I am currently working on a TypeScript API where I have merged all the data from this API with some additional data obtained from another API function. I have provided a snippet of my code which adds data to the first index of an array. M ...

Transferring Files from Bower to Library Directory in ASP.Net Core Web Application

Exploring ASP.Net Core + NPM for the first time, I have been trying out different online tutorials. However, most of them don't seem to work completely as expected, including the current one that I am working on. I'm facing an issue where Bower ...

Modifying the delimiter used in paste range feature of ag-grid

Is there a way to enable pasting tab separated data into an ag-grid column instead of a row? Currently, when pasting newline separated data it goes into columns and tab separated goes into rows. The documentation suggests using the "clipboardDeliminator" ...

What is included in the final Angular build package selection?

Is there a tool available to track packages included in the final build of an Angular project? For instance: I am using the package "@angular/compiler" as a dependency in my package.json, but it is not a dev dependency. According to the Angular ...

What is the best way to organize a redux state to meet these specific needs?

In managing a complex web application state, it is crucial to keep track of multiple elements such as selected items and display IDs. The application may house several instances of these "States" with only one being active at any given time. For instance, ...

Utilizing the useContext hook within a strictly Typescript-based class component

I have developed a pure Typescript class that serves as a utility class for performing a specific task. Within this class, I have created a context that is intended to be used universally. My goal is to utilize this context and its values within the pure T ...

What is the best way to transfer information within the same webpage?

https://i.sstatic.net/umfln.pnghttps://i.sstatic.net/9W6ZE.pngI'm just starting out with angular 2/4 projects and I have a popup search tab in the interface that displays an editable list. However, I am unsure about how to transfer data to the main i ...

The attribute 'pixiOverlay' is not found in the property

Working on my Angular 8 project, I needed to display several markers on a map, so I chose to utilize Leaflet. Since there were potentially thousands of markers involved, I opted for Leaflet.PixiOverlay to ensure smooth performance. After installing and imp ...

Button click does not trigger component reload

Presented below is a button element that triggers the following action when clicked: <button mat-button (click)="toggleLikeQuestion(question['id'])" aria-label="Like this question."> {{!isQuestionLike ...

Access to property 'foo' is restricted to an instance of the 'Foo' class and can only be accessed within instances of 'Foo'

In my Typescript code, I encountered an error with the line child._moveDeltaX(delta). The error message reads: ERROR: Property '_moveDeltaX' is protected and only accesible through an instance of class 'Container' INFO: (me ...

React-table fails to show newly updated data

I am facing an issue with my react-table where real-time notifications received from an event-source are not being reflected in the table after data refresh. https://i.stack.imgur.com/q4vLL.png The first screenshot shows the initial data retrieval from th ...

Develop a TypeScript class in a distinct file

I currently have ag-grid implemented in an Angular project with a CustomFilter. The problem is that the file containing the code for the CustomFilter function is becoming quite large and difficult to manage. I am now looking to move the CustomFilter to a s ...