尝试 return Angular select 选项的值和 innerText

Trying to return both the value and innerText of Angular select option

这是我的负载示例

    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=” },

我想 return select 选项的值和内部文本,所以值“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=
}

尝试 return Angular select 选项的值和 innerText

基本上这就是我想要做的

http://jsfiddle.net/5bzkfwrt/

你需要改变这个:

 (change)="doSomething($event,test.value)"

在 .ts 中

doSomething(event,value) {
      console.log(value); 

}