0

I have two drop down in html. First dropdown is giving the selected value but the second dropdown is return as undefined.

component.html

<form class="form row">
<div class="inputGroup inputGroup--medium">
        <label class="inputGroup__label is-required">Product</label>
        <div class="selectWrapper">
          <select id="selectProduct"  class="inputGroup__select" [(ngModel)]="selectedProduct"
            (ngModelChange)="setProductVersion($event)"[ngModelOptions]="{standalone: true}">
            <option selected value="" disabled>Select Product</option>
            <option *ngFor="let product of Products" [value]="product.name">
              {{ product.name}}
            </option>
          </select>
        </div>
      </div>
 <div class="inputGroup inputGroup--medium">
        <label class="inputGroup__label is-required">Product Version</label>
        <div class="selectWrapper">
          <select id="selectProductVersion" class="inputGroup__select"           
          [(ngModel)]="selectedProductVersion" [ngModelOptions]="{standalone: true}">
          <option selected value="" disabled>Select Product Version</option>
            <option *ngFor="let pVersion of ProductsVersion" [value]="pVersion.name">
              {{ pVersion.productVersion}}
            </option>
          </select>
        </div>
      </div>
</form>

component.ts

 selectedProduct:any;
    selectedProductVersion:any;

 setProductVersion(event){
  const filteredResult = this.AllProductsVersion.filter(x=> x.productName ==this.selectedProduct);
  this.ProductsVersion=filteredResult;
 }

this.AllProductsVersion is Json data. and i'm able to set the product version based on selected product using this function.

selectedProduct is giving the result whatever is selected in dropdown but selectedProductVersion is giving as undefined.

7
  • What exactly you want to do?? like what is the functionality of this? Commented May 24, 2021 at 7:35
  • i have to post the selectedProduct and selectedProductVesion to the API. hence selected values are required. Commented May 24, 2021 at 7:37
  • So is second dropdowns' values are based on the selected value of first dropdown? Commented May 24, 2021 at 7:39
  • yes. second dropdown values are based on first dropdown. so i'm calling the (ngModelChange)="setProductVersion($event)" to set the values in second dropdown. Commented May 24, 2021 at 7:41
  • You should share some typescript as well. Commented May 24, 2021 at 7:42

1 Answer 1

1

try changing this:

 <option selected value="" disabled>Select Product Version</option>
            <option *ngFor="let pVersion of ProductsVersion" [value]="pVersion.productVersion">
              {{ pVersion.productVersion}}
            </option>
Sign up to request clarification or add additional context in comments.

15 Comments

i'm using the correct variable.this.ProductsVersion will return the filteredResult which i'm iterating in html ngFor loop.
Okk so when would be the data comes in selectedProductVersion variable.?
when the second dropdata data is selected [(ngModel)]="selectedProductVersion" this should save the selection and assign it to selectedProductVersion variable. however for firstdrop down it's working fine.
Okk, will you be able to show data in second dropdown list for selection?
yes. in second dropdown data is coming based on first dropdown selection. but i'm not able to get the selected data from second drop down to selectedProductVersion variable
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.