Swaroop Babaleshwar
Swaroop Babaleshwar

Reputation: 211

how to set the <ng-option> value in angular 5

<ng-select  [(ngModel)]="filtersMaster.granularity">
     <ng-option *ngFor="let opt of granularityJSONData" value="opt.val"> 
       {‌{opt.content}}  
     </ng-option>
</ng-select>

where granularityJSONData contents are, after selecting an option from the dropdown, it does not hold the exact value of that particular content

EX - from drop down if i select Recent 5 Min then value it shd hold is 5, but instead of that it contains opt.val, how to fix this ?

{
 "content" : "Recent 5 Min",
 "val" : "5"
 },

Upvotes: 2

Views: 6806

Answers (1)

Krishna Rathore
Krishna Rathore

Reputation: 9687

you can try this solution

add [value] in ng-option element

<ng-select  [(ngModel)]="filtersMaster.granularity"  >

     <ng-option *ngFor="let opt of granularityJSONData" [value]="opt.val"> {‌{ opt.content }  </ng-option>

</ng-select>

Upvotes: 3

Related Questions