[英]Select Item Always Returns [object, Object]
I'm trying to get a simple form working in angular.我正在尝试获得一个在 angular 中工作的简单表格。 It has a select box, setup like this:
它有一个 select 盒子,设置如下:
<select formControlName="tag1" (ngModelChange)="changeTag1($event)">
<option *ngFor="let up of uploadMock" [ngValue]="up" [value]="up.tagCode">{{up.tagName}}</option>
</select>
I want to get it's value when it posts back.我想在它回发时获得它的价值。 But, the value is always [object, Object], even when I inspect it using Chrome.
但是,该值始终是 [object, Object],即使我使用 Chrome 检查它也是如此。
What am I doing wrong?我究竟做错了什么? I can't understand why it's so difficult to get the value of a select box.
我不明白为什么很难获得 select 盒子的价值。
Try like this:试试这样:
.html .html
<select formControlName="tag1" (change)="changeTag1($event.target.value)">
<option *ngFor="let up of uploadMock" [value]="up.tagCode">{{up.tagName}}</option>
</select>
.ts .ts
changeTag1(evt) {
console.log(evt)
}
You are doing correct but you need to remove ngValue, you can use value in this way:你做得对,但你需要删除 ngValue,你可以通过这种方式使用value :
<option *ngFor="let order of orders; let i = index" [value]="orders[i].id">
within the select HTML tag.在 select HTML 标签内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.