I am working on Angular 4 Web API Here when selecting an option it will display packingtypename its working fine. but my problem is when clicking add button it will only save the packingtypeID i want Packing type id and packing type name Here i want to like this when selecting a PackingTypeName automatically pass their ID to API. which means when selecting a packing type Name and press add button the selected Name and its ID can be saved to DB. actually, I am new in angular. can anyone help please its a big help form me
my Html code is
<label>Packing Type</label>
<select class="form-control" id="PackingtypeName" placeholder="name" name="PackingtypeName" (change)="onSelect($event.target.value)" *ngIf="products">
<option value="0" disabled>Please Select Packing type </option>
<option *ngFor="let item of products" id={{item.PackingTypeID}} value={{item.PackingTypeID}}>{{item.PackingtypeName}}</option>
</select>
<input type="button" value="Add Item"[disabled]="!itemdetails" class="btn btn-success" (click)="addItems(newStockoutForm.value);newStockoutForm.reset()" />
my TS file
addItems(value: any) {
this.items = new IComboDetails(this.PackingTypeID, value.PackingtypeName, );
console.log(this.PackingTypeID);
alert(this.PackingTypeID);
alert(value.PackingtypeName);// here show alert is PackingTypeID
}
onSelect(PackingTypeID: number) {
alert(PackingTypeID);
this._loginService.selectedpackingtypeid = PackingTypeID;
this.PackingTypeID = PackingTypeID