0

I am new to Angular. I want to have a drop down with ng-options.

I have a end point which is returning the back end data. For example my back end data has 1, 2 , 3 ,4, 5. While displaying with the ng-options I don't want to display the first value.

(i.e I want in my drop down box only 2,3,4,5)

I have the following code:

<select class="form-control" ng-options="num as num for num in numbers id="no_num" ng-model="no.number" required> </select>
Navnish Bhardwaj
  • 1,687
  • 25
  • 39

2 Answers2

0

Assuming you don't want to implement a filter option in your backend, you think you're probably looking for the filter called filter.

There's another StackOverflow question that I believe answers this exact question.

Community
  • 1
  • 1
sdegroot
  • 237
  • 3
  • 11
0

If you don't want to display the first value of list :[1, 2 , 3 ,4, 5]. I would suggest to use ng-repeat in option tag and prevent first value 1 with ng-if :

In controller:

$scope.numbers=[1, 2 , 3 ,4, 5];

In HTML:

<select ng-model="value">
   <option ng-repeat="number in numbers" value="number" ng-if="number!=1">{{number}}</option>
</select>

You can also use $first to prevent first value like this:

<select ng-model="value">
   <option ng-repeat="number in numbers" value="number" ng-if="!$first">{{number}}</option>
</select>
Ajit Soman
  • 3,926
  • 3
  • 22
  • 41