How to Create a Dependency on Tabs for Selecting Items in an Angular 7 Materials Dropdown List

I am currently working with angular 7 in combination with angular materials.

In my project, I have implemented a tab as well as a selection list. What I aim to achieve is that the items displayed in the selection list are dependent on the chosen tab in the tab-group.

At present, I am contemplating the best approach to make this functionality possible. One idea I had was to create a function that dynamically generates a new list based on two existing lists and a common property within the data.

The tab-group primarily consists of alphabet letters, which would then be added as a property to the objects within the list.

Would you happen to know a more efficient way to accomplish this task?

This is how my code looks like:

 <mat-tab class="error-label mat-tab-labels-errors" *ngFor="let areaItem of areaList, let i = index"
<mat-list-option *ngFor="let err of errors" [value]="err.id">

Within the TypeScript file:

areaList: string[] = ['A', 'B', 'C', 'D', 'L', 'T'];
  errors = [
    { id: 'A7', clientName: 'fd', type: 'A' },
    { id: 'B1', clientName: 'sdfdfsu', type: 'B' },
    { id: 'E3', clientName: 'sdf', type: 'C' },
    { id: 'I2', clientName: 'fsdfu', type: 'D' },
    { id: 'L', clientName: 'sdfsf', type: 'L' },
    { id: 'L', clientName: 'sdfsf', type: 'T' }
  ];

Answer ā„–1

<mat-form-field>
  <mat-select (selectionChange)="updateSelection($event.value)">
    <mat-option *ngFor="let option of choices" [value]="option.type">
      {{option.type}}
    </mat-option>
  </mat-select>
</mat-form-field>

<mat-tab-group [selectedIndex]="currentSelection"
               (selectedIndexChange)="setCurrentSelection($event)">
  <mat-tab *ngFor="let tab of currentTabs; let index = index" [label]="tab">
    Contents for {{tab}} tab
  </mat-tab>
</mat-tab-group>

currentTabs = ['A', 'B', 'C', 'D', 'L', 'T'];
currentSelection = new FormControl(0);
choices = [
  { id: 'A7', clientName: 'fd', type: 'A' },
  { id: 'B1', clientName: 'sdfdfsu', type: 'B' },
  { id: 'E3', clientName: 'sdf', type: 'C' },
  { id: 'I2', clientName: 'fsdfu', type: 'D' },
  { id: 'L', clientName: 'sdfsf', type: 'L' },
  { id: 'L', clientName: 'sdfsf', type: 'T' }
];

updateSelection(event)
{
    console.log(event);
    this.currentSelection = new FormControl(this.currentTabs.indexOf(event));    
}

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

Using TypeScript to type styled-system props

Currently, I am utilizing styled-system and one of the main features of this library is its shorthand props that allow for simple and quick theming. Although I have streamlined my component, a significant aspect lies here: import React from 'react&a ...

What are the steps to create an object from an array?

Is it possible to create an object from an array in TypeScript? { A: {H: 10, W: 20, S: 30}} using the following data: [ { group: A, name: H, value: 10 }, { group: A, name: W, value: 20}, { group: A, name: S, value: 30} ] L ...

What is the proper way to utilize the ES6 import feature when using a symbolic path to reference the source file?

I am seeking a deeper understanding of the ES6 import function and could use some assistance. The Situation Imagine that I have a portion of code in my application that is frequently used, so I organize all of it into a folder for convenience. Now, in t ...

Using the concat operator along with the if statement in Angular to make sequential requests based on certain conditions

Managing multiple HTTP requests in a specific order is crucial for my event. To achieve this, I am utilizing the concat operator from rxjs. For instance, upon receiving data from the first request, I update local variables accordingly and proceed to the ne ...

Using two type arguments, create a feature selector with ngrx

Currently, I am delving into the world of ngrx with Angular v6.0.9 and AngularCLI v6.0.8. In an example application, there is a demonstration on creating a root level createFeatureSelector with two type arguments: example-app/app/reducers/index.ts ..... ...

Experimenting with Date Object in Jest using Typescript and i18next

I have included a localization library and within my component, there is a date object defined like this: getDate = () => { const { t } = this.props; return new Date().toLocaleString(t('locale.name'), { weekday: "long", ...

Encountering a 500 error code while attempting to send a post request using Angular

Whenever I attempt to send a post request to Django server, I encounter a 500 (Internal Server Error) response. Interestingly, the get and put requests work flawlessly on the same server where Django is connected to PostgreSQL database. Here is a snippet ...

The wss websocket connection is experiencing issues in Firefox 89 when attempting to connect on localhost

For some reason, the websocket wss connection is not working in Firefox 89 when trying to connect on localhost. Interestingly, I can successfully establish a connection using my to connect to from the production server. However, when attempting to init ...

Typescript error in RxJS: Incorrect argument type used

I came across this code snippet from an example in rxjs: Observable.fromEvent(this.getNativeElement(this.right), 'click') .map(event => 10) .startWith({x: 400, y: 400}) .scan((acc, curr) => Object.assign({}, acc, {x: acc ...

Utilizing TinyMCE with Angular 2: Customizing Editor Content with @Input Parameters

I am new to using Tinymce and I am unsure about where exactly I should place the setContent(this.content) method. The current setup I have is giving me an error: TypeError: null is not an object (evaluating 'body.nodeName') --- runTask ā€” zone. ...

Tips on customizing the appearance of the dropdown calendar for the ngx-daterangepicker-material package

Is there a way to customize the top, left, and width styling of the calendar? I'm struggling to find the right approach. I've been working with this date range picker. Despite trying to add classes and styles, I can't seem to update the app ...

What is the best way to convert the text on a button into another language?

Currently, I am facing an issue with translating a button using Angular. The translation appears to be outside of the button in question. Additionally, there is another problem that I have encountered. For reference, here is a sample: https://i.stack.i ...

When fetching data from the API in Angular, the response is displayed as an object

After fetching data from the API, I am encountering an issue where the "jobTitle" value is not displaying in the table, but instead appears as an array in the console. Can someone assist me with resolving this problem? Below is the visibility.ts file: exp ...

Angular populates the id property of the mode with the dropdown's display value instead of the actual id

I successfully implemented a dropdown in my Angular application, but I am facing an issue when submitting the form. Instead of displaying the Id, it is showing the display text in the model. What could be causing this problem? To my understanding, all I ne ...

Tips for troubleshooting JSON sorting in Angular

I am currently troubleshooting column positions within my application and need to inspect the sorted column definition. After retrieving the column definition from my API, I proceed to sort them. However, I also want to log the sorted list/Array to my co ...

Tips for enabling the TypeScript compiler to locate bokeh's "*.d.ts" files

I recently made the switch from Bokeh's convenient inline extension framework to their npm based out of line build system. I'm currently working on getting my extension to build, but I've noticed that Bokeh organizes all TypeScript *.ts.d fi ...

The Background Geolocation feature is throwing an error: "Subscribe method is not present in the Promise<any> type."

I am currently using Ionic 4 to build an app that tracks the user's location every hour using GPS. To achieve this, I utilized the Ionic 4 Background Location plugin as per their official documentation. I followed the code to install the plugin which ...

What are some best practices for integrating ES2020 into an Angular project?

Below is the content of my tsconfig.json file: { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap&q ...

When the session times out in Angular 5, the previous user's credentials remain on the page instead of being replaced with the current user's information

When switching from one user to another in Angular 5, I am facing an issue where the previous user's credentials are displayed instead of the current user's until I refresh the page. I have tried using the localstorage.clear() method but it doesn ...

The upcoming development does not involve creating an entire HTML webpage using on-demand static site generation (SS

Iā€™m encountering a problem when utilizing getStaticPaths and getStaticProps to create an on-demand SSG for a sharing page. My setup involves Next v12.1.0 and React 17.0.2. After building a specific /[id] page, I can retrieve the data but the HTML output ...