这是我的有效载荷示例
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'</p>
我的 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 </p>
基本上这就是我想要做的
<a href="http://jsfiddle.net/5bzkfwrt/" rel="nofollow noreferrer">http://jsfiddle.net/5bzkfwrt/