1

I don't know how to change this, but whenever I use my select option, it always goes to null.

This is my HTML code,

<select type="number" class="footer" id="chooser" 
        ng-change="selectchange(selectedPage)" 
        ng-model="selectedPage" min="1"
        ng-options="x for x in pages">
    <option value="" selected="false" hidden>
</select>

Is there any reason it changes to null. Because when it changes it sends another request to angular.

What is the problem here, and how to solve it?

enter image description here enter image description here

enter image description here

5
  • what do you mean by null and where? Commented Apr 29, 2018 at 18:05
  • @Sajeetharan I have 2-3 options in my select. So when I select one, say the second option, it takes that value and then automatically goes to a null value that I did not even put in the options. This results in my code getting another request as the value in the select options has been changed for a second time. I read somewhere that angular puts a null option in select but I didn't understand how to counter it. Commented Apr 29, 2018 at 18:11
  • @Sajeetharan I have put pictures up for more context Commented Apr 29, 2018 at 18:15
  • edit your question with your js code you probably missing something there Commented Apr 30, 2018 at 6:14
  • Share your js code including selectchange and console.log statements. Commented Apr 30, 2018 at 6:29

2 Answers 2

1

Use this in html

<select class="footer" id="chooser" ng-change ="selectchange()" ng-model="selectedPage" ng-options="x in pages"></select>

And in your controller:

$scope.selectedPage = "1";
$scope.pages = [1, 2, 3, 4];
$scope.selectchange = function() {
  console.log("selectedPage changed to : ", $scope.selectedPage);
}

For more information read https://docs.angularjs.org/api/ng/directive/select

Sign up to request clarification or add additional context in comments.

Comments

0

You have set the option value to null and it always selected by selected tag. So it select null value every time, remove that option value and use ng-options to set the options in your selected box. No need to use option tag.

<select type="number" class="footer" id="chooser" 
    ng-change="selectchange(selectedPage)" 
    ng-model="selectedPage" min="1"
    ng-options="x for x in pages">
<-- <option value="" selected="false" hidden> -->   // remove this line
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.