1

I have a dynamic combo box. I want to initialise the value of all combo boxes like this the image below is from adding static values like this

  $scope.newObject ={  0 : "N/P" ,1 : "N/P",2 : "N/P",3 : "N/P"}

enter image description here

so I tried to make for on each item on the list in this code below:

$scope.inifonction = ["N/P","N/A","OK","KO"];
//this is the option inside the combobox
$scope.displaydata = function(index) {

    $scope.id = index;

    $http.get("/fonctions?id=" + $scope.id).success(function(data) {
        $scope.list = data;

        for(i=0;i<$scope.list.length;i++)
        {
            $scope.tab = $scope.list[i].idfonction
            //this to get the id of the list in a tab 


            console.log($scope.tab)

        //[1,6,5,3] exemple of data in the console 

        $scope.newObject ={  tab : "N/P"}
        }
    });

but I didn't work and it looked like this:

enter image description here

and here's my HTML

 <select  ng-model="newObject[l.idfonction]"  ng-options="  fct for fct in inifonction "  class="form-control">

when I insert the data am getting this as a result of that ng-model

Object {1: "N/A", 2: "OK", 3: "N/A", 4: "N/P", tab: "N/P"}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Kamel Mili
  • 1,374
  • 3
  • 19
  • 43

2 Answers2

2

Add this line to every dropdown option in the view:

<option value = "">N/P</option>

UPDATE:

I can see that you have an array specific for the initial values. You could use that to set the value as:

<option value = "">{{inifonction[0]}}</option> //This prints N/P

More, you could set to a scope and use it as :

$scope.tab = "N/P";

<option value = "">{{tab}}</option>

Sajal
  • 4,359
  • 1
  • 19
  • 39
  • i tried to make it like that but it didn't work maybe cuzz it my ng-model= object – Kamel Mili May 20 '16 at 16:13
  • first thanks for answering me ! i have the data i just want to set a default value inside the ` – Kamel Mili May 20 '16 at 16:27
0

this fixed my issue i hope it helps you all

<select ng-init="newObject[l.idfonction] = inifonction[0] " ng-model="newObject[l.idfonction]"  ng-options="  fct for fct in inifonction "  class="form-control">
Kamel Mili
  • 1,374
  • 3
  • 19
  • 43