locked
Cannot set drodown value while editing in angular4 RRS feed

  • Question

  • User483994611 posted

    I have a grid clicking on edit button it will open a pop up where all text boxes and dropdown values will be pre populated and user can update</div> <div>The ProductType dropdown is not populating the selected value which is in DB it is showing "Please Select" ...need help where i am doing wrong

    editProduct(_product: Product) {
    //Show edit dialog
    this.displayEditDialog = true;

    this.isEdit = true;
    this.isAdd = false;

    this.product = { Id: _product.Id, Name: _product.Name, Category: _product.Category, Price: _product.Price,ProductTypeId: _product.ProductTypeId };
    }

    <label class="col-md-1 control-label" style="width: 122px;" for="ProductTypeId">Product Type</label>
    <div class="col-md-12">
    <select class="form-control" formControlName="ProductTypeId" required [(ngModel)]="selectedProductType" (change)="onSelect($event)" >
    <option value="undefined">Please select</option>
    <option *ngFor="let producttype of producttypes"
    [ngValue]="producttype.ProductTypeId">
    {{producttype.ProductTypeName}}
    </option>
    </select>

    onSelect(args) {

    alert(args.target.value);
    alert(args.target.options[args.target.selectedIndex].text);
    this.selectedProducttype = args.target.value;

    }

    Thursday, July 18, 2019 9:42 AM

All replies

  • User839733648 posted

    Hi suvo,

    According to your description, I'm sorry that I could not reproduce your issue successfully.

    suvo

    I have a grid clicking on edit button it will open a pop up where all text boxes and dropdown values will be pre populated and user can update. The ProductType dropdown is not populating the selected value which is in DB it is showing "Please Select" ..

    It seems that you have a grid that show the data from database, and when click button, the pop up will show the detailed information, right?

    I'd like to ask that if the value show on the grid correctly.

    I suggest that you may try to test separately to see if you could get the dropdownlist's value.

    I've made a simple demo and when you set the default value it will show successfully.

    https://stackblitz.com/edit/angular-7wyytn 

    I hope this will be helpful to you.

    Or you may also make a example that may reprodcue your issue in that site( https://stackblitz.com/ ) and this may be easier to help with you.

    Best Regards,

    Jenifer

    Friday, July 19, 2019 7:17 AM