0

This is my object

$scope.status = [{ "code": "CNA", "name": "Consignee Not Available" }, { "code": "TBD", "name": "To Be Delivered" }, { "code": "CRA", "name": "Consignee Refused To Accept" }, { "code": "D", "name": "Delivered" } ]

my HTML is as follows

<select ng-options="status.name for status in status" ng-model="awb.delivery_fail_reason"> <option value="">Please Select Status</option> </select>

so what I want is

  1. when user selects the status To be Delivered my model variable awb.delivery_fail_reason should be set to TBD
  2. when model awb.delivery_fail_reason is TBD it should automatically set select to To Be Delivered Is this possible ?
3
  • 1
    try status.code as status.name for status in status
    – bazz
    Commented Oct 3, 2013 at 8:12
  • I never knew we can do this type of stuff. Thank you very much.
    – c2h5oh
    Commented Oct 3, 2013 at 8:14
  • No worries, I have moved it to the answer section for future reference.
    – bazz
    Commented Oct 3, 2013 at 8:16

2 Answers 2

1

try

status.code as status.name for status in status
0

make changes in html as below

  <select ng-model="awb.delivery_fail_reason">
              <option value="">Please Select Status</option> 
              <option ng-repeat="s in status" value="{{s.code}}">{{s.name}}</option>

              </select>

try fiddle http://jsfiddle.net/U3pVM/1489/

1
  • Word of caution !! Never ever use ng-repeat with option. There is already ng-options which will allow you to repeat over objects.
    – c2h5oh
    Commented Oct 3, 2013 at 12:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.