0

I would like to have the first element of my ng-options to be the default one:

<select data-ng-options='item.pk for item in items' data-ng-click='update()'></select>

(so this is different than having an <option value=''>Default</option> at the end of the select. I also would like update() to be called at the beginning (on the default option). How can I achieve this ?

1

1 Answer 1

1

First you want to create a model for the select element:

<select ng-model="selectedItem" ng-options="item.pk for item in items"
     ng-click="update()">
</select>

After that, in your controller, you want to set selectedItem to the first element in items, and call your update function:

$scope.selectedItem = $scope.items[0]; $scope.update();

Notice that you should define update before calling it.

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

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.