Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I receive this json from a service after client call.

JSON

    [ {
   "Accreditment" : {
      "Id" : "1",
      "Creator" : "John Smith",
      "IdCreator" : "1",
      "CreationDate" : "2014-07-01T18:13:51+02:00",
      "CostCenter" : [ "5411-Channel1", "5412-Channel2" ],
      "Destination" : [ "Playout Channel1", "Playout Channel2" ],
      "IdUserEnabled" : [ "1", "2" ],
      "WorkOrderType" : [ "New Asset", "Subtitling" ],
      "StartDate" : "2013-05-04T18:13:51+02:00",
      "EndDate" : "2014-10-04T18:13:51+02:00",
      "Status" : "enabled"
   }
} ] 

I want get select option value in my controller

THIS IS MY LIST OPTION

"CostCenter" : [ "5411-Channel1", "5412-Channel2" ],

and this is my html with select HTML

    <form role="form">
  <div class="form-group row more-margin-top" ng-repeat="work in WorkOrder">
    <div class="col-xs-12">
      <label>Selezione centro di costo</label> <select class="form-control" ng-change="selectAction()">
        <option ng-model="myOption" ng-repeat="cost in work.Accreditment.CostCenter" value="{{cost}}">
          {{cost}}
        </option>
      </select>
    </div><!-- /.col-xs-3 -->
  </div>
</form>

CONTROLLER

mwm3.controller('CreateWorkOrderCtrl',function($scope){
    $scope.selectAction=function(){
        //HERE I WANT MY SELECT OPTION SELECTED
    };

});

HOW CAN DO IT? thanks in advance

UPDATE---------------

HTML

<div class="form-group" ng-repeat="work in WorkOrder">

                          <div class="row more-margin-top">
                                <div class="col-xs-12">
                                    <label>Selezione centro di costo</label>
                                    <select class="form-control" ng-model="myOption" ng-change="selectAction()">
                                        <option  ng-repeat="cost in work.Accreditment.CostCenter" value="{{cost}}">{{cost}}</option>
                                    </select>
                                </div><!-- /.col-xs-3 -->

                            </div>
</div>

but i receive undefined in log in my controller

share|improve this question
3  
If you are looking for the selected value then you need to move ng-model to the select, not the option and use $scope.myOption. –  Sergiu Paraschiv Jul 4 at 13:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.