这是我的有效载荷的一个例子
0: { category: “BRAINS”,
description: "test 1234124”,
userNumber: “789456123”,
accountType: “WOW”,
balance: {amount: 12.34, currency: “USD”},
uniqueId: “47823748923hfhjfew32847hw43879=” },
1: { category: “DIET”,
description: "test 1234124”, userNumber: “123456789”,
accountType: “WOW”,
balance: {amount: 43.21, currency: “GBP”},
uniqueId: “47823748923hfhjfew32847hw43879=” },
2: { category: “MEAT”,
description: "test 1234124”,
userNumber: “951234679”,
accountType: “WOW”,
balance: {amount: 26.56, currency: “EUR”},
uniqueId: “47823748923hfhjfew32847hw43879=” },
我想同时返回值和选择选项的内部文本,因此同时返回值'uniqueId'和内部文本'userNumber'
我的HTML
<select #category="ngModel" name=“user” id=“user” class="form-control" #test [(ngModel)]="model.user” (change)="doSomething(test.value)">
<option *ngFor="let user of users” [value]=“user.uniqueId”>
{{user.userNumber}}
</option>
</select>
我的.ts文件
doSomething(value) {
console.log(value);
// returns the value 47823748923hfhjfew32847hw43879=
}
onAddValue() {
console.log('yoyoyoy', this.model);
// returns {value: undefined, uniqueId: "47823748923hfhjfew32847hw43879="}
console.log('accountNumber', this.model.user); //returns 47823748923hfhjfew32847hw43879=
}
试图同时返回Angular选择选项的值和innerText
基本上这就是我想要做的
答案 0 :(得分:0)
您需要更改此内容:
(change)="doSomething($event,test.value)"
在.ts
中doSomething(event,value) {
console.log(value);
}