仅选择一个选项,不显示名称,不显示角度4中的名称 [英] Selecting an option only Display Id not Name in angular 4
问题描述
我选择一个选项,它会显示packingtypename其工作正常,当这里工作角4的Web API.但是我的问题是,当单击添加按钮时,它只会保存我想要的包装类型ID和包装类型名称.在这里,我想在选择PackingTypeName时自动将其ID传递给API.这意味着在选择包装类型名称时,按下添加按钮,可以将所选名称及其ID保存到DB.实际上,我是新手.任何人都可以帮忙,这对我有很大帮助
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
我的HTML代码是
<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()" />
我的TS文件
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
推荐答案
在ts文件名-PackingItem = {};
从value={{item.PackingTypeID}}
更改为[value]="item"
然后在addItem()
方法中检查console.log(this.PackingItem);
如果您有任何疑问,请告诉我.
Let me know if you have any doubt.
这篇关于仅选择一个选项,不显示名称,不显示角度4中的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!