javascript - Make a NG-Options value select in same function as populating list -


i having difficulties selecting value array in same function populate select using ng-options. trying dynamically load select list full of options , @ same time there default value last time user chose want selected. when console.logging can see works , added machineprofile.input select not reflect ng-model has current value. did confirm both same. have code below.

 $scope.getmachineprofile = function(object) {      var count = 0;     var keepgoing = true;      $scope.machineprofile.machinename = object.name;      $scope.machineinputs = object.hardware;     /*angular.foreach(object.hardware, function(inputs, key) {        console.log($scope.machineinputs);     });*/      //var foundmachine = 0;     angular.foreach($scope.machineprofiles, function(machine, key) {       if (keepgoing) {         if (machine.remoteaddr === object.address) {           keepgoing = false;             /*$timeout(function(){            }, 500);*/           /*console.log($scope.machineprofiles[count].input);           console.log($scope.machineprofile.input);*/           $scope.machineprofile.input = $scope.machineprofiles[count].input;           $scope.machineprofile.worktype = $scope.machineprofiles[count].worktype;           $scope.machineprofile.workperiod = $scope.machineprofiles[count].workperiod;           $scope.machineprofile.counterrate = $scope.machineprofiles[count].counterrate;           $scope.machineprofile.timerrate = $scope.machineprofiles[count].timerrate;           console.log($scope.machineprofile);           //console.log('awesome select: ' + count);           //console.log($scope.machineprofiles[count].input);         }         ++count;       }     }); 

html

<ul class="nav sidebar-menu">         <li ng-repeat="machine in machineobj" class="">             <a ng-click="getmachineprofile(machine)">                 <span class="fa fa-cogs"></span>                 <span class="sidebar-title">{{machine.name}}</span>             </a>         </li>     </ul> 

below once item selected code above:

<div class="col-sm-4">         <div class="form-group">             <label for="chooseinput" class="control-label">choose input</label>             <!-- <select name="chooseinput" class="form-control"  ng-model="machineprofile.input">                 <option ng-selected="machine.input === machineprofile.input" ng-repeat="machine in machineinputs" value="machine.input">                     {{machine.input === machineprofile.input}}                 </option>             </select> -->             <select name="chooseinput" class="form-control" ng-model="input" ng-change="awesome(machineprofile.input)" ng-options="machine.input machine in machineinputs track machine.input"></select>             <!-- <input disabled="true" name="machinename" type="text" class="form-control" placeholder="machine name"> -->         </div>     </div> 

any appreciated driving me nuts. $scope object machineprofile.input updated nothing appears on screen.

looks ng-model not correct. try this.

<select name="chooseinput" class="form-control" ng-model="machineprofile.input" ng-change="awesome(machineprofile.input)" ng-options="machine.input machine in machineinputs track machine.input"></select> 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -