-1

My task is very simple. I'm able to set values to text boxes that come from restful api.. I'm able to get and display on the raw HTML page using {{currentCommodity.commodityName}} But, not able to set values to the select tag even though I'm able to get value.

My code is

$scope.editCommodity = function(commodityIndex) {           
        console.log("commodities object",$scope.commoditiesAdded[commodityIndex].commodityName);            
        $scope.currentCommodity.commodityName = $scope.commoditiesAdded[commodityIndex].commodityName;

}

It returns a commodity name with paddy..

My HTML code

---{{currentCommodity.commodityName}}-
<select class="form-control selection_size" ng-change="selectunits(currentCommodity.commodityName.commodityID)" ng-model="currentCommodity.commodityName" ng-disabled="{{editBusinessFlag}}" ng-options="commodityitem.commodityName for commodityitem in commodityList">
    </select>

Any help would be greatly appreciated.

Manwal
  • 23,450
  • 12
  • 63
  • 93
  • I'm not sure I fully understood the requirement but would this be of any help? [**getting the ng-object selected with ng-change**](http://stackoverflow.com/questions/14386570/getting-the-ng-object-selected-with-ng-change) – Nope Aug 25 '14 at 08:44
  • Can you please share it in jsfiddle? – Archana Aug 25 '14 at 08:46
  • @Archana, its very simple. I just want to assign the value to the select tag. I wish that I could create a fiddle, but I can't now. – Mahesh Muppala Aug 25 '14 at 09:00
  • Ok Mahesh i will try to give a solution for your problem – Archana Aug 25 '14 at 09:15
  • I think the answer in that question can help you : http://stackoverflow.com/questions/17815036/setting-default-value-in-select-drop-down-using-angularjs?lq=1 – Asenar Aug 25 '14 at 09:59

1 Answers1

1

Try following code:

    You selected : {{currentCommodity.commodityName}}
    <select class="form-control selection_size" ng-model="currentCommodity" ng-options="commodityitem.commodityName for commodityitem in commodityList">   
    </select>
Atur
  • 1,712
  • 6
  • 32
  • 42
nitin
  • 3,747
  • 2
  • 24
  • 31