2

In my edit page, what I need is to show the value in drop down list where the value is coming from a json file. I am able to get the value in html file but struggling in showing this value as selected.

Here's the html code:

<select class="form-control" name="manufacturer" ng-change="loadModels(cameraDetails.manufacture_id.id);" ng-model="cameraDetails.manufacture_id" ng-options="manufacturer.name for manufacturer in manufacturers" required>
    <option value="">{{'PLEASE_SELECT' | translate}}</option>
</select> 
{{cameraDetails.manufacture_id}}  // Here I am getting the value.  

json file:

{
    "ip": "10.103.01.0",
    "name": "Camera axiss",
    "description": "Description text here",
    "manufacture_id": "SONY",
    "modelId": "Model XYZ001",
    "user_name": "user",
    "password": "pass",
    "isEnableCamera": true,
    "hasMasking": true,
    "hasPresetCamera":true,

    "userGroup": {
        "userGroupIds": "Group 2"
    }

}           

I saw similar issue (How do I set default value of select box in angularjs) but that dint worked for me.

any help would be a great help.

Community
  • 1
  • 1
MonsterJava
  • 423
  • 7
  • 23
  • 1
    It seems that `cameraDetails.manufacture_id` not maching with option values in drop down. Try ``ng-options="manufacturer.manufacture_id as manufacturer.name for manufacturer in manufacturers" `` – Sameer K Jul 07 '16 at 07:56
  • When you are doing the ng repeat why are you keeping the value="" try passing some value and then check. – Rohan Jul 07 '16 at 07:56

1 Answers1

-1

You can do it in following way

 <select class="form-control" name="manufacturer" ng-change="loadModels(cameraDetails.manufacture_id.id);" ng-model="cameraDetails.manufacture_id"  required>
                               <option ng-repeat="m in manufacturers" value="m.ip">{{m.name}}</option>
                            </select>

Here is working example http://jsfiddle.net/phd975zo/

jitender
  • 10,238
  • 1
  • 18
  • 44
  • My question was "I am able to get the value in html file but struggling in showing this value as selected.".. @jitender – MonsterJava Jul 18 '16 at 09:26