Search code examples
angulardropdown

Hot to get id and name from dropdown in angular 4?


In angular 4 .ts i want to use both accounts.Id and accounts.Name from dropdown. can it be possible?

<select [(ngModel)]="selectedName" class="form-control" (change)="SearchLedgerTransaction($event.target.value)">
      <option value=""></option>
      <option *ngFor="let accounts of accountledger" [value]="accounts.Id && accounts.Name">
          {{accounts.Name}}
      </option>
  </select>
  <br />
  {{selectedName}} Account Ledger View

Solution

  • you can use something like..

    <select [(ngModel)]="selectedName" class="form-control" (change)="SearchLedgerTransaction($event.target.value)">
        <option value=""></option>
        <option *ngFor="let accounts of accountledger" [value]="accounts">
            {{accounts.Name}}
        </option>
    </select>
    <br />
    {{selectedName.Id}}{{selectedName.Name}} Account Ledger View