Selected value from a dropdown not displayed while editing the page

10 views
Skip to first unread message

Rakhee Menon

unread,
Feb 17, 2018, 5:08:46 AM2/17/18
to Angular and AngularJS discussion
Hi Everyone,

This is an error which occurs frequently in my project even though 'id' has been declared in its respective class.I am not able to figure it out what exactly is the issue....Here in my project when I go into editing any particular page... using  ngModel, I am trying to get the selected value from a dropdown list and also value from a textbox. The value from the textbox is displayed but the selected value from a dropdown is not seen  only the list of items is shown..It says that id of undefined.Can anyone help me with it??Please check the code below..

Thanks & Regards,
Rakhee

ERROR TypeError: Cannot read property 'id' of undefined
    at Object.eval [as updateRenderer] (ItemCategoryDetailComponent.html:82)
    at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13105)
    at checkAndUpdateView (core.es5.js:12256)
    at callViewAction (core.es5.js:12599)
    at execEmbeddedViewsAction (core.es5.js:12557)
    at checkAndUpdateView (core.es5.js:12252)
    at callViewAction (core.es5.js:12599)

<div class="form-group col-md-6" >
<label for="category_name">Category Name</label>
<input
formControlName="category_name"
class="form-control"
id="category_name"
placeholder="Enter Item Name"
[(ngModel)]="category.category_name">
<!-- <div *ngIf="itemCategory.touched && itemCategory.invalid"class="alert alert-danger">
<div *ngIf="itemCategory.errors.required">Category Name is required</div>
</div> -->{{ category.item_grp_id.group_name}}
</div>
<div class="form-group col-md-6">
<label for="item_grp_id">Group Name</label>
<select
formControlName="item_grp_id"
class="form-control select2"
id="item_grp_id"
style="width: 100%;"
(keydown) = "getAllGroups()"
(ngModelChange)="getAllGroups()"
[(ngModel)]="category">
<!-- <option value="" disabled></option> -->
<option>
{{ category.item_grp_id.group_name}}
</option>
<option *ngFor="let itemgroup of itemgroups"[value]="itemgroup.id"[selected]="itemgroup.id === category.item_grp_id.id">
{{ itemgroup.group_name }}
</option>
</select>
Reply all
Reply to author
Forward
0 new messages