javascript - How to translate ids to objects in ng-option angular? -


i have array of ids , need use array source of ng-option directive inside of select. find objects corresponding id in collection , create array of objects use instead of array of ids wonder there way of doing dynamicaly somehow? setting function source of ng-option?

you can of filtering id inside ngoptions directive expression:

angular.module('demo', []).controller('mainctrl', function($scope) {      $scope.ids = [1, 4];      $scope.objects = [          {id: 1, name: 'one'},          {id: 2, name: 'two'},          {id: 4, name: 'four'}      ];  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"></script>  <div ng-app="demo" ng-controller="mainctrl">        <pre>{{objects}}</pre>      <pre>{{ids}}</pre>        <select ng-model="model"               ng-options="id (objects | filter:{id: id})[0].name id in ids">      </select>        {{model}}    </div>


Comments