Go through the elements of a Dropdown (Select Option) with $ interval AngularJS

1

I need to go through the elements of a dropdownlist that I have previously filled with a service, that stays in one element for 30 seconds and then moves on to the next one.

My HTML:

 <select ng-model="depSel" ng-change="changedValue(depSel)" class="form-control pull-right animated fadeInRight" style="width: 260px;font-size:17px;">
        <option value="">--- Seleccione Dependencia ---</option>
        <option ng-repeat="dependencia in dependencias" value="{{dependencia}}">{{dependencia}}</option>
  </select>

My app.js:

$scope.dependencias = {};
    DepSrv.cargar().then( function(){
    $scope.dependencias = DepSrv.config.data.DEPENDENCIAS;
});

Greetings.

    
asked by Shadowcast 06.06.2017 в 23:39
source

1 answer

0

One option could be to cycle over the dependency array and update the ng-model:

  $scope.index = 0;

  $interval(function() {
    $scope.index = ($scope.index == $scope.dependencias.length)? 0: $scope.index +1;
    $scope.depSel = ($scope.index == $scope.dependencias.length) ? $scope.dependencias[0] : $scope.dependencias[$scope.index + 1];
  }, 30000);

I leave an example in plunker to see if it really is what you need: link

I hope it's what you're looking for, if it's not, do not hesitate to ask again. Greetings.

    
answered by 06.06.2017 в 23:55