Updating the alignment between two input mat-select in Angular materialAlternatively:Fine-tuning the reference between

I am currently working on an Angular 6 app:

I have two mat-select inputs that I want to connect in a way that if the selected option in my First select is equal to the value 'AAA', then the Second select should be hidden.

  • First Mat-Select -> 'AAA'
  • Second Mat-Select -> hidden

I have attempted something like this:

       <div class="form-group">
          <label class="col justify-content-start">Encryption Mode</label>
          <mat-form-field class="col" >
            <mat-select placeholder="Select encryption mode" formControlName="encryptionMode" #FirstSelect>
              <mat-option *ngFor="let modeCh of encryptionModeData" [value]="modeCh.value">
                {{modeCh.viewValue}}
              </mat-option>
            </mat-select>
          </mat-form-field>
          </div>

          <div class="form-group" *ngIf="!(FirstSelect== 'AAA')">
            <label class="col justify-content-start">Key Files</label>
            <mat-form-field class="col" >
              <mat-select placeholder="Select file" formControlName="keyFiles">
                <mat-option *ngFor="let modeCh of encryptionModeData" [value]="modeCh.value">
                  {{modeCh.viewValue}}
                </mat-option>
              </mat-select>
            </mat-form-field>
          </div>

Unfortunately, this approach is not functioning as expected.

Any suggestions?

Answer №1

The mechanism you are utilizing is actually a Material Element (placed on a mat-select).

As that element incorporates the ControlValueAccessor interface, you can treat it similar to an HTMLInputElement.

This implies your condition should be implemented as follows:

*ngIf="!(FirstSelect.value == 'AAA')"

Alternatively, if you are using a reactive form instance, you could simply use:

*ngIf="!(myForm.get('modeChiffrement').value == 'AAA')"

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

Disabling eslint does not prevent errors from occurring for the unicorn/filename-case rule

I have a file called payment-shipping.tsx and eslint is throwing an error Filename is not in camel case. Rename it to 'paymentShipping.tsx' unicorn/filename-case However, the file needs to be in kebab case since it's a next.js page that s ...

Is Angular9 BehaviorSubject from rxjs giving trouble across different components?

I am facing an issue with updating data in real-time from the profile component to the header component. Initially, it works fine but after updating any value in the profile component, the header observable does not subscribe again. To solve this problem, ...

The attribute 'data' is not found in the type 'IntrinsicAttributes & IProps'. Error code: ts(2322)

I encountered the following issue: Error: Type '{ data: never; }' is not compatible with type 'IntrinsicAttributes & IProps'. The property 'data' does not exist on the type 'IntrinsicAttributes & IProps'. import { ...

Tips for adjusting the size and positioning the ng bootstrap carousel in the center

My Angular project is using ng bootstrap, but I'm facing a styling issue. The content doesn't display in the center, rather it appears in the upper left corner: example I would like the content to be centered and wide under the blue headbar. W ...

Bringing in the typescript 4 package to use in typescript version 3.8.3

I've been working on a project that is utilizing typescript 3.8.3, and I'm currently attempting to import a newer package (specifically win32-api). I initially didn't anticipate any issues since the package is compiled to JavaScript. At wor ...

Transferring css to an external file within an angular 4 component by utilizing webpack

I encountered this specific error message: Error: Anticipated 'styles' to be a collection of strings. Despite the fact that I have clearly defined the styles as an array of strings: styleUrls: ['./app.component.css'] Can anyone pinp ...

Showing canvas lines while dragging (using only plain JavaScript, with React.JS if needed)

Is there a way to add lines with two clicks and have them visible while moving the mouse? The line should only be drawn when clicking the left mouse button. Any suggestions on how I can modify my code to achieve this functionality? Currently, the lines are ...

Angular 6: Issue with displaying data on the user interface

Hello! I am attempting to fetch and display a single data entry by ID from an API. Here is the current setup: API GET Method: app.get('/movies/:id', (req, res) => { const id = req.params.id; request('https://api.themoviedb.org/ ...

Setting up Datatable in Angular 2+ without relying on jQuery

I need assistance with initializing a datatable for a table that has a unique id. Can you provide guidance on the syntax to achieve this? Here is an example of my table structure: <table id="myDataTable"> <thead> <tr> ...

Angular does not update the progress bar

Imagine having a component html with your own customized round progress bar <round-progress #progress [current]="current" </round-progress> The "Current" value represents the percentage. In my TypeScript component, I have written: ...

Perplexed by the persistent failure of this Jasmine test accompanied by a vexing "timer in queue" error

I'm attempting to test a function that uses RxJS to broadcast long press events to subscribers. Below is the implementation of the function: export function watchForLongPress(target: HTMLElement) { let timer: number; const notifier = new Subject& ...

Prevent all dates from being selected except for the last day of every month in the Angular Material Calendar component

Is it possible to restrict all dates except the final day of each month with Angular Material? I need users to only be able to select this particular date. There is a [matDatepickerFilter] property, but it seems to work only for a specific list of dates. ...

Angular's input event fails to trigger for dynamically generated fields when pasted into them

When working with a form that has dynamically generated input fields, I encountered an issue. I needed to display a preview of the input contents on a div while pasting content into the fields. This project is built using Angular 11. Below is my .ts file: ...

Access uninitialized properties in Typescript post-compilation

I am currently in the process of creating a wrapper for socket.io. Coming from a strong object-oriented background, I aim to incorporate the idea of Models into my framework/wrapper. For those familiar with socket.io, you may know that data associated wit ...

Angular version 7.2.1 encounters an ES6 class ReferenceError when attempting to access 'X' before it has been initialized

I have encountered an issue with my TypeScript class: export class Vehicule extends TrackableEntity { vehiculeId: number; constructor() { super(); return super.proxify(this); } } The target for my TypeScript in tsconfig.json is set to es6: ...

Displaying data labels overlaid on top of data points in line charts

Currently, I am utilizing Angular2 along with ng2-charts to generate a line chart. My objective is to position the data labels directly above the points, similar to how they appear in the bar chart showcased in this image: bar chart I stumbled upon the ch ...

Having trouble with clearInterval in React TypeScript?

I have been encountering issues with the clearInterval function in TypeScript for React. I am not sure why the interval is not being cleared. To address this problem, I defined a variable let interval_counter;, and used it as follows: interval_counter = ...

Ensuring type integrity for intersections containing varying numbers of elements

Currently, I am navigating a sophisticated custom typeguard library developed for a project I'm involved in. I am facing challenges in grasping the concept of function signatures used in typeguards. The library includes a generic Is function that has ...

There seems to be a compatibility issue between Angular 16 and Bootstrap 5 styling

In my angular.json, I have defined my styles in the following way: "styles": [ { "input": "node_modules/bootstrap/dist/css/bootstrap.min.css", "bundleName": "ltrCSS" }, { "input": "node_mod ...

Exploring Angular 2 MVC for debugging JavaScript

I'm currently troubleshooting my main controller, but I can't seem to find it in the dev tools along with my service. Is there a way for me to debug my JavaScript files without using TypeScript? Below is an image of my project structure which I s ...