1
I have multiple records which are stored in 

$scope.myQuality

variable currently in in below attached plnkr but that data will be coming from rest api. Currently i have used ng-options for display select options which i am getting from $scope.items. Depending upon the value of ("status": true) i want to make the dropdown value selected to "OK"

If

("status": true)

-> selected value in dropdown should be OK

If

("status": false)

-> selected value in dropdown should be KO

If

("status": null)

-> selected value in dropdown should be empty

Each record will have dropdown but it's selected value will differ depending on the value of status within

$scope.myQuality

Please find the below url

http://plnkr.co/edit/aW5enrHuEZ2jHiQuHQmV?p=preview

Id Date Status {{ roll. id}} {{ roll. date | date:"dd/MM/yyyy HH:mm" }}

script.js

// Code goes here

angular.module('sortApp', [])

.controller('mainController', function($scope) { $scope.sortType = 'id'; // set the default sort type $scope.sortReverse = false; // set the default sort order $scope.searchLists = ''; // set the default search/filter term

$scope.items =[
    {"value":true,"text":"OK"},
    {"value":false,"text":"KO"}
];

   $scope.myQuality = [
  {
            "id": 1,
            "status": true,
            "date": 1474864500000,
  }, {
            "id": 2,
            "status": false,
            "date": 1474741800000,
  },{
            "id": 3,
            "status": null,
            "date": 1474914600000,
  },{
            "id": 4,
            "status": true,
            "date": 1474914600000,
  },{
            "id": 5,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 6,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 7,  
            "status": true,
            "date": 1474914600000,
  },{
            "id": 8,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 9,  
            "status": true,
            "date": 1474914600000,
  },{
            "id": 10,  
            "status": false,
            "date": 1474914600000,
  },{
            "id": 11,  
             "status": true,
            "date": 1474914600000,
  },{
            "id": 12,  
            "status": false,
            "date": 1474914600000,
  }   ] });
3
  • have updated the plnkr url. Commented Oct 6, 2016 at 19:19
  • @jinishshah it's better to include the code in your post than to link to it from a third party site. eventually, your plunkr link will break, making this post useless to future users having similar problems. Commented Oct 6, 2016 at 19:22
  • 1
    @TheHeadRush have included the code. if anything more is required please let me know. also share how it can be done. Commented Oct 6, 2016 at 19:34

1 Answer 1

1

Just remove the track by from your ng-options, plnkr below:

https://plnkr.co/edit/olbqvp2GiTTqr1JUyeSq?p=preview

ng-options="option.value as option.text for option in items"
Sign up to request clarification or add additional context in comments.

5 Comments

Excellent. I was trying to understand, but I believe the track by is correct. Thanks!
If you need the null option also, you can put in items the value: {"value":null,"text":""}
@gustavo gabriel - But the options value attribute is now set to boolean:true & boolean:false. I want it to be set to true & false only.
@jinishshah I dont know what you mean by options value, they are working as true and false..
@GustavoGabriel i mean by the option value <option label="OK" value="boolean:true" selected="selected">OK</option> instead it should appear as <option label="OK" value="true" selected="selected">OK</option>. since depending on that value i have to do some task & open popup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.